vb 如何打开文件已存在对话框

来源:百度知道 编辑:UC知道 时间:2024/05/02 16:35:34
现做一保存文件程序,发现如果文件已经存在,也不进行提示,直接保存,请教各位大侠,应该怎么写才正确?谢谢!
下面贴出我的代码:
CommonDialog1.Filter = "(*.bin)|*.bin"
CommonDialog1.ShowSave
If CommonDialog1.FileName <> "" Then
Open CommonDialog1.FileName For Binary As #2
For i = 0 To 511
Put #2, , arrBuf(i)
Next i
Close #2
End If

CommonDialog1.Filter = "(*.bin)|*.bin"
CommonDialog1.ShowSave
If CommonDialog1.FileName = "" Then Exit Sub'//没有选中文件退出过程
If Dir(CommonDialog1.FileName)<>"" Then '//如果文件已经存在
If Msgbox("文件已经存在,是否要覆盖?",vbYesNo)=vbYse Then Goto SaveFile
Else
Goto SaveFile
End If
Exit Sub
SaveFile:
Open CommonDialog1.FileName For Binary As #2
For i = 0 To 511
Put #2, , arrBuf(i)
Next i
Close #2