Windows2003 Standard Edition + VB6.0(SP6)大家好,我用RICHTEXTBOX做了一个类似windows记事本的小程序,以下分别是"保存"和"另存为"的代码Private Sub mnuFileSave_Click()
Dim sFile As String
If Left$(Me.Caption, 8) = "无标题" Then
With dlgCommonDialog 'dlgCommonDialog = CommonDialog
.DialogTitle = "保存"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
rtfDoc.SaveFile sFile 'rtfDoc = RichTextBox
Me.Caption = sFile
gblnDirty = False '在模块中:Public gblnDirty As Boolean ,判断文档是否被修
'改过,如:Private Sub rtfDoc_Change()
'gblnDirty = True
'End Sub
Else
sFile = Me.Caption
rtfDoc.SaveFile sFile
gblnDirty = False
End If
End SubPrivate Sub mnuFileSaveAs_Click()
Dim sFile As String
With dlgCommonDialog
.DialogTitle = "另存为"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
sFile = .FileName
End With
rtfDoc.SaveFile sFile
gblnDirty = False
End Sub但是当保存时,输入的文件名与现有文件的文件名相同时程序就强行保存在现有文件中(在弹出的对话框
中无论按"保存"或"取消")
所以自己想用Msgbox做一个询问是否覆盖原有文件的提示,代码如下Private Sub mnuFileSave_Click()
Dim sFile As String
If Left$(Me.Caption, 8) = "无标题" Then
With dlgCommonDialog
.DialogTitle = "保存"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
ElseIf .FileName = .FileName Then
MsgBox "文件已存在,是否覆盖?", vbYesNoCancel
If vbYes Then
rtfDoc.SaveFile sFile
Me.Caption = sFile
gblnDirty = False
Else
Return
End If
End If
sFile = .FileName
End With
rtfDoc.SaveFile sFile
Me.Caption = sFile
gblnDirty = False
Else
sFile = Me.Caption
rtfDoc.SaveFile sFile
gblnDirty = False
End If
End SubPrivate Sub mnuFileSaveAs_Click()
Dim sFile As String
With dlgCommonDialog
.DialogTitle = "另存为"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
ElseIf .FileName = .FileName Then
MsgBox "文件已存在,是否覆盖?", vbYesNoCancel
If vbYes Then
rtfDoc.SaveFile sFile
Me.Caption = sFile
gblnDirty = False
Else
Return
End If
End If
sFile = .FileName
End With
rtfDoc.SaveFile sFile
gblnDirty = False
End Sub之后运行并测试了一下,结果超级失败!
我知道这个问题是MONKY级的,但请大家给出一个完整的严谨的"保存"和"另存为",谢谢!
Dim sFile As String
If Left$(Me.Caption, 8) = "无标题" Then
With dlgCommonDialog 'dlgCommonDialog = CommonDialog
.DialogTitle = "保存"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
End If
sFile = .FileName
End With
rtfDoc.SaveFile sFile 'rtfDoc = RichTextBox
Me.Caption = sFile
gblnDirty = False '在模块中:Public gblnDirty As Boolean ,判断文档是否被修
'改过,如:Private Sub rtfDoc_Change()
'gblnDirty = True
'End Sub
Else
sFile = Me.Caption
rtfDoc.SaveFile sFile
gblnDirty = False
End If
End SubPrivate Sub mnuFileSaveAs_Click()
Dim sFile As String
With dlgCommonDialog
.DialogTitle = "另存为"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
sFile = .FileName
End With
rtfDoc.SaveFile sFile
gblnDirty = False
End Sub但是当保存时,输入的文件名与现有文件的文件名相同时程序就强行保存在现有文件中(在弹出的对话框
中无论按"保存"或"取消")
所以自己想用Msgbox做一个询问是否覆盖原有文件的提示,代码如下Private Sub mnuFileSave_Click()
Dim sFile As String
If Left$(Me.Caption, 8) = "无标题" Then
With dlgCommonDialog
.DialogTitle = "保存"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
ElseIf .FileName = .FileName Then
MsgBox "文件已存在,是否覆盖?", vbYesNoCancel
If vbYes Then
rtfDoc.SaveFile sFile
Me.Caption = sFile
gblnDirty = False
Else
Return
End If
End If
sFile = .FileName
End With
rtfDoc.SaveFile sFile
Me.Caption = sFile
gblnDirty = False
Else
sFile = Me.Caption
rtfDoc.SaveFile sFile
gblnDirty = False
End If
End SubPrivate Sub mnuFileSaveAs_Click()
Dim sFile As String
With dlgCommonDialog
.DialogTitle = "另存为"
.CancelError = False
.Filter = "文本文件(*.txt)|*.txt|所有文件|*.*"
.ShowSave
If Len(.FileName) = 0 Then
Exit Sub
ElseIf .FileName = .FileName Then
MsgBox "文件已存在,是否覆盖?", vbYesNoCancel
If vbYes Then
rtfDoc.SaveFile sFile
Me.Caption = sFile
gblnDirty = False
Else
Return
End If
End If
sFile = .FileName
End With
rtfDoc.SaveFile sFile
gblnDirty = False
End Sub之后运行并测试了一下,结果超级失败!
我知道这个问题是MONKY级的,但请大家给出一个完整的严谨的"保存"和"另存为",谢谢!
解决方案 »
- vb6怎么和vb.net实现进程间通讯?
- 把一行如何分割成几列?
- 关于如何实现 对象列表框 的问题?急!急!急!
- 动态创建的控件如何设置只读属性?
- 如何解决?ACCESS提示"由于您和其他用户试图同时改变同一数据,导致Microsoft Jet 数据库引擎停止进程"
- VB调用DELPHI编写的DLL后产生的错误?
- text1.text里有多行文本我用什么方法能全部取出来呢?
- 不好意思,请教一个关于SHELL函数的问题(在线等待)
- 怎样与服务器进行时间同步??
- 请教VB远程连接SQL SERVER2000数据库!谢谢!
- 我是VB盲,想问大家一个比较简单的问题?
- mscomm手机通讯怎么取消发送?
Private Sub Command1_Click()
CommonDialog1.Flags = cdlOFNOverwritePrompt'这样就如果文件已经存在就会有提示了
CommonDialog1.ShowSave
End Sub