需要帮助解决此错误 [英] Need Help WIth this error

查看:100
本文介绍了需要帮助解决此错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dim sfd As New SaveFileDialog
            sfd.Filter = "Text Document (.txt)|*.txt"
            Dim sv As String
            sfd.ShowDialog()
            sv = sfd.FileName
            Dim sw As New StreamWriter(sv) <---ERROR HERE
                sw.Write(RichTextBox1.Text)
            sw.Close()



弹出的错误

{空路径名称不合法。}

我正在使用vs 2010 Express


the error that pops up
{"Empty path name is not legal."}
I'm using vs 2010 Express

推荐答案

您应该检查ShowDialog的返回值,并且只有在返回值为mea时才会执行某些操作ns用户已按下OK。

用户也可以取消操作,然后sfd.FileName将为空。

You should check the return value of ShowDialog and only look do something if the return value means that the user has pressed OK.
The user can also cancel the operation and then sfd.FileName will be empty.
if (sfd.ShowDialog() == DialogResult.OK) // Sorry for the c# syntax
{
    Dim sw As New StreamWriter(sfd.FileName)
    sw.Write(RichTextBox1.Text)
    sw.Close()
}


消息很明确: sv 是一个空字符串(虽然它必须包含有效的路径名)。

你必须正确处理这种情况(例如,当用户点击 SaveFileDialog 's'取消'按钮时)。
The message is clear: sv is an empty string (while it must contain a valid path name).
You have to properly handle such scenarios (for instance when the user clicks on the SaveFileDialog's 'Cancel' button).


这篇关于需要帮助解决此错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆