
VB 保存文件时点击取消出现实时错误52
想将计算的结果保存在文本文件里,代码如下:PrivateSubCommand2_click()CommonDialog1.FileName="*.txt"CommonDi...
想将计算的结果保存在文本文件里,代码如下:
Private Sub Command2_click()
CommonDialog1.FileName="*.txt"
CommonDialog1.Filter=" txt file|*.txt|all file|*.* "
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
print #1 "消耗量" &Chr(13)&Chr(13)&Chr(13)&Val(Tex2t.Text)
Close 1
End Sub
保存文件没有问题,但是点取消后出现实时错误 52 错误的文件名或号码 展开
Private Sub Command2_click()
CommonDialog1.FileName="*.txt"
CommonDialog1.Filter=" txt file|*.txt|all file|*.* "
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
print #1 "消耗量" &Chr(13)&Chr(13)&Chr(13)&Val(Tex2t.Text)
Close 1
End Sub
保存文件没有问题,但是点取消后出现实时错误 52 错误的文件名或号码 展开
3个回答
展开全部
这个是个BUG,要自行处理错误的。
Private Sub Command2_click()
on error goto hh
CommonDialog1.FileName="*.txt"
CommonDialog1.Filter=" txt file|*.txt|all file|*.* "
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
print #1 "消耗量" &Chr(13)&Chr(13)&Chr(13)&Val(Tex2t.Text)
Close 1
exit sub
hh:
End Sub
Private Sub Command2_click()
on error goto hh
CommonDialog1.FileName="*.txt"
CommonDialog1.Filter=" txt file|*.txt|all file|*.* "
CommonDialog1.ShowSave
Open CommonDialog1.FileName For Output As #1
print #1 "消耗量" &Chr(13)&Chr(13)&Chr(13)&Val(Tex2t.Text)
Close 1
exit sub
hh:
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
当你点击取消时,CommonDialog1.ShowSave后面的这几句,还会顺序执行,所以会报错。
Open CommonDialog1.FileName For Output As #1
print #1 "消耗量" &Chr(13)&Chr(13)&Chr(13)&Val(Tex2t.Text)
Close 1
因此,这里,你需要把点取消的情况考虑进来进行处理。
if CommonDialog1.FileName<>"*.txt" then ' "*.txt"是你前面指定的值
else
endif
Open CommonDialog1.FileName For Output As #1
print #1 "消耗量" &Chr(13)&Chr(13)&Chr(13)&Val(Tex2t.Text)
Close 1
因此,这里,你需要把点取消的情况考虑进来进行处理。
if CommonDialog1.FileName<>"*.txt" then ' "*.txt"是你前面指定的值
else
endif
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把CommonDialog的CancelError属性设置为False就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询