Private Sub Form_Load()
q = FreeFile
Open "d\note.txt" For Input As #q
Input #q, g
Close #q
Label5.Caption = g
end sub
-----------------------
CommonDialog1.FileName = ""
CommonDialog1.InitDir = "save\"
CommonDialog1.Filter = vbofnfilemustexist
CommonDialog1.Filter = "所有文件(*.*)|*.*|文本文件(*.txt)|*.txt"
CommonDialog1.FilterIndex = 2
CommonDialog1.Flags = 2
CommonDialog1.DialogTitle = "打开文件"
CommonDialog1.Action = 1
m = CommonDialog1.FileName
Open m For Input As #q
……
每次打开“保存对话”框,如果按“取消”就会出错。提示是“运行时错误“75”;
路径/文件访问错误”
參考答案:错误是因为取消后m返回filename的值为空,这样打开文件时会出错。
可以加入:
On Error GoTo PROC_EXIT
CommonDialog1.CancelError = True
CommonDialog1.FileName = ""
………………………………
PROC_EXIT:
Exit Sub
这样取消时就不做任何操作。