Dim Filename As String
Dim F As Integer

Public Function ExitApp() As Integer

    Dim ans1 As String

    ans1 = MsgBox("Would you like to save your work?", vbYesNoCancel)

If ans1 = vbYes Then
    
    CommonDialog1.Filter = "all files (*.*)|*.*|text _Files (*.txt)|*.txt|batch files (*.bat)|*.bat"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.ShowSave
    Filename = CommonDialog1.Filename
    F = FreeFile
    Open Filename For Output As #F
    Print #F, Text1.Text
    Close #F
    ExitApp = 0
ElseIf ans1 = vbNo Then
    ExitApp = 0
Else
    ExitApp = 1
    MsgBox ("Have you got a death wish!?")
    
End If

End Function


Private Sub Form_Load()
    Timer1.Interval = 1000
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    Cancel = ExitApp
End Sub

Private Sub Save_Click()
    On Error GoTo errhandler
    CommonDialog1.Filter = "all files (*.*)|*.*|text _Files (*.txt)|*.txt|batch files (*.bat)|*.bat"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.ShowSave
    Filename = CommonDialog1.Filename
    F = FreeFile
    Open Filename For Output As #F
    Print #F, Text1.Text
    Close #F
errhandler:
    MsgBox ("Stop wasting my time")
    Form1.Show
Exit Sub
End Sub

Private Sub Open_Click()
    CommonDialog1.Filter = "all files (*.*)|*.*|text _Files (*.txt)|*.txt|batch files (*.bat)|*.bat"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.ShowOpen
    Filename = CommonDialog1.Filename
    F = FreeFile
    Open Filename For Input As #F
    Text1.Text = Input$(LOF(F), F)
    Close #F
Exit Sub
End Sub

Private Sub Command3_Click()
    Text1.Text = ""
    Text1.SetFocus
End Sub

Private Sub Command4_Click()
    Unload Me
End Sub

Private Sub mnuexit_Click()
    Unload Me
End Sub

Private Sub mnuopen_Click()
    CommonDialog1.Filter = "all files (*.*)|*.*|text _Files (*.txt)|*.txt|batch files (*.bat)|*.bat"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.ShowOpen
    Filename = CommonDialog1.Filename
    F = FreeFile
    Open Filename For Input As #F
    Text1.Text = Input$(LOF(F), F)
    Close #F
End Sub

Private Sub mnusave_Click()
    CommonDialog1.Filter = "all files (*.*)|*.*|text _Files (*.txt)|*.txt|batch files (*.bat)|*.bat"
    CommonDialog1.FilterIndex = 2
    CommonDialog1.ShowSave
    Filename = CommonDialog1.Filename
    F = FreeFile
    Open Filename For Output As #F
    Print #F, Text1.Text
    Close #F
End Sub


Private Sub Timer1_Timer()
    Label1.Caption = Time
End Sub

    Source: geocities.com/matkins70