Save a (.txt) File On Form Closing

Post new topic   Reply to topic

View previous topic View next topic Go down

Save a (.txt) File On Form Closing

Post  conorsteel on Sun Aug 31, 2008 5:31 pm

Things You'll Need
1 RichTextBox [RichTextBox1]

Select The Form_Closing Event

Type The Following Code:

Code:
Dim reply
        reply = MsgBox("Do you want to Save before you Exit?", 52)
        If reply = 6 Then
            Dim SFD As New SaveFileDialog
            With SFD
                .Filter = "Text Files (.txt)|*.txt"
                If .ShowDialog = Windows.Forms.DialogResult.OK Then

                    Dim SW As New IO.StreamWriter(.FileName)
                    For Each line As String In RichTextBox1.Lines
                        SW.WriteLine(line)
                    Next
                    SW.Flush()
                    SW.Close()
                End If
            End With
        Else
        End If




This is all you need to do to save a (.txt) file when your form is closing.
To test your program, debug it then go to the location where you saved your file.

conorsteel
Admin
Admin

Number of posts: 13
Age: 16
Location: Kilmarnock, Scotland
Registration date: 2008-08-31

View user profile http://homefinanceviewer.webs.com

Back to top Go down

View previous topic View next topic Back to top


Permissions of this forum:
You cannot reply to topics in this forum