filestream无法将流写入文件

来源:百度知道 编辑:UC知道 时间:2024/05/25 05:49:31
以下是我的代码:
public sub savecut
Dim fs As New FileStream("./set.ini",FileMode.Create,FileAccess.Write)
Dim sw As New StreamWriter(fs)
sw.WriteLine("写入点东西")
sw.close
fs.close
end sub

以上这个程序片段使用的时候,直接调用可以使用。

但是当用如下语句调用就不行了:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dim opensub as new openfiledialog
If opensub.ShowDialog = Windows.Forms.DialogResult.OK Then
savecut()
End If
End Sub
上面不管if判断成功与否,都无法将流写入文件,不知道到底是怎么回事,还请高手帮忙解决一下。

dim像是VB的声明

将声明dim opensub as new openfiledialog
调到声明组里,置于所有语句之首

调试一下,看看能否行得通

不行的话,错误的提示一定指向if ……then上,那就是你的if判断错了

还有VB声明时,没有Private Sub、End Sub

................高手

首先声明俺一点儿也不懂

你先把if去掉,就是无论什么条件都得直接调用那个函数/过程
要是不成功....
要是成功.......

我看你下边这段和上边好象有点儿不同?