首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

求问一个简单的CommonDialog控件的有关问题

2012-02-04 
求问一个简单的CommonDialog控件的问题。我用CommonDialog控件对话保存一个文件。CommonDialog1.ShowSaveCom

求问一个简单的CommonDialog控件的问题。
我用CommonDialog控件对话保存一个文件。
  CommonDialog1.ShowSave
  CommonDialog1.Filter = "(*.dat)|*.dat"
  strFileName = CommonDialog1.FileName
  If Dir(strFileName) <> "" Then
  If MsgBox("文件已经存在,是否覆盖?", vbInformation + vbOKCancel, "提示") = vbCancel Then
  Exit Sub
  End If
  End If
 为什么对话框出来时我点击“取消”按钮,没有退出该对话框,而是出来“文件已经存在,是否覆盖”再点击取消才退出。
这个是那个地方设置不对,请朋友们指正一下,谢谢!

[解决办法]
If Dir(strFileName) <> "" And strFileName <> "" Then '增加一个判断
[解决办法]

on error resume Err
CommonDialog1.ShowSave
CommonDialog1.Filter = "(*.dat)|*.dat"
strFileName = CommonDialog1.FileName
If Dir(strFileName) <> "" Then
If MsgBox("文件已经存在,是否覆盖?", vbInformation + vbOKCancel, "提示") = vbCancel Then
Err: Exit Sub
End If
End If

[解决办法]

VB code
Option ExplicitPrivate Sub Command1_Click()        Dim strFileName As String                On Error GoTo ErrTocjl                CommonDialog1.ShowSave        CommonDialog1.CancelError = True        CommonDialog1.Filter = "(*.dat)|*.dat"        strFileName = CommonDialog1.FileName        If strFileName <> "" Then           If Dir(strFileName) <> "" Then              If MsgBox("文件已经存在,是否覆盖?", vbInformation + vbOKCancel, "提示") = vbCancel Then                 Exit Sub              Else                 '覆盖的代码              End If           End If        End IfErrTocjl:End Sub 

热点排行