我的工程里面使用了CommonDialog用来存放文件的,但是在运行的时候会发现老是报错,报的是:Path/File access error.
我存放文件的程序是:
Public Sub SaveData()  If Not Success Then
       MsgBox "通讯失败"
       Exit Sub
  Else
  
     Dim mfile As String
     Dim hour2 As Integer
     Dim minute2 As Integer
      '---使用通用对话框,控件名就是CommonDialog-----   
     Form1.CommonDialog.Filter = "txt file|*.txt"
     Form1.CommonDialog.ShowSave
     mfile = Form1.CommonDialog.FileName
       '-----存成文本文件---
     Open mfile For Append As #1
     Write #1, "日期", "时间", "数据"
     For i = 1 To Data_Len
     hour2 = i \ 4
     minute2 = (i Mod 4) * 15
'     Write #1, month2, date2, hour2, minute2, Data(i)
     Print #1, month2 & "\";
     Print #1, date2 & Space(2);
     Print #1, hour2 & ":";
     Print #1, minute2 & Space(4);
     Print #1, Data(i)
     Next i
     Close   End If
End Sub
谢谢谢谢

解决方案 »

  1.   

    LZ怎么又开一帖?!'使用CommonDialog的CancelError判断吧,将其设为False就不会报错,不过建议
    '你在打开文件前,必须先判断文件是否存在,即:dir(mfile)<>"",才进行下步操作。
    '关于CancelError参考回帖:http://community.csdn.net/Expert/topic/4453/4453456.xml?temp=.8662989
      

  2.   

    设置CommonDialog的CancelError为False后,返回文件名为空字符串"",故如果文件名不为"",你
    就打开文件.
    或者是CancelError设为True,在ShowSave前添加On Error Goto ...,在错误处理段,你在处理.
    参考回帖: 
    http://community.csdn.net/Expert/topic/4453/4453456.xml?temp=.8662989