dim lastfilename 第一次保存 弹出对话框 lastfilename=Commondialog.filename saveto lastfilename第二次保存 if lastfilename<>"" then saveto lastfilename end if
我的程序大致如下,我希望不要有太多的全局变量产生。 Private Sub mnu_save_Click() Dim filenum As Integer
On Error Resume NextWith savefile .CancelError = True On Error GoTo ErrHandler .Flags = cdlOFNExplorer Or _ cdlOFNLongNames Or _ cdlOFNHelpButton .DialogTitle = "保存文件" .InitDir = "D:\communication\" .filter = "所有文件(*.*)|*.*|文本文件" & _ "(*.c2)|*.c2|批文件(*.bat)|*.bat" .FilterIndex = 2 .ShowSave End WithIf savefile.filename <> "" Then filenum = FreeFile() Open savefile.filename For Output As #filenum Write #filenum,**** Close filenum End If
Dim filenum As Integer Static strFN As String On Error Resume Next If Dir(strFN) = "" Then With savefile .CancelError = True On Error GoTo ErrHandler .Flags = cdlOFNExplorer Or cdlOFNLongNames Or cdlOFNHelpButton .DialogTitle = "保存文件" .InitDir = "D:\communication\" .Filter = "所有文件(*.*)|*.*|文本文件" & "(*.c2)|*.c2|批文件(*.bat)|*.bat" .FilterIndex = 2 .ShowSave End With strFN = savefile.FileName End If If Dir(strFN) <> "" Then filenum = FreeFile() Open savefile.FileName For Output As #filenum Write #filenum,**** Close filenum End If
Commondialog.DialogTitle="文件另存为"
Commondialog.InitDir="D:\"
Commondialog.Filter="*.Txt"
Commondialog.ShowSave
........
第一次保存
弹出对话框
lastfilename=Commondialog.filename
saveto lastfilename第二次保存
if lastfilename<>"" then
saveto lastfilename
end if
Private Sub mnu_save_Click()
Dim filenum As Integer
On Error Resume NextWith savefile
.CancelError = True
On Error GoTo ErrHandler
.Flags = cdlOFNExplorer Or _
cdlOFNLongNames Or _
cdlOFNHelpButton
.DialogTitle = "保存文件"
.InitDir = "D:\communication\"
.filter = "所有文件(*.*)|*.*|文本文件" & _
"(*.c2)|*.c2|批文件(*.bat)|*.bat"
.FilterIndex = 2
.ShowSave
End WithIf savefile.filename <> "" Then
filenum = FreeFile()
Open savefile.filename For Output As #filenum
Write #filenum,****
Close filenum
End If
Dim filenum As Integer Static strFN As String On Error Resume Next If Dir(strFN) = "" Then With savefile
.CancelError = True On Error GoTo ErrHandler .Flags = cdlOFNExplorer Or cdlOFNLongNames Or cdlOFNHelpButton
.DialogTitle = "保存文件"
.InitDir = "D:\communication\"
.Filter = "所有文件(*.*)|*.*|文本文件" & "(*.c2)|*.c2|批文件(*.bat)|*.bat"
.FilterIndex = 2
.ShowSave
End With strFN = savefile.FileName
End If If Dir(strFN) <> "" Then
filenum = FreeFile()
Open savefile.FileName For Output As #filenum
Write #filenum,****
Close filenum
End If