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级的,但请大家给出一个完整的严谨的"保存"和"另存为",谢谢!