Read and write to a text file

This will read and write to a text file

Simply creat a windows form and cut an paste the following then add 2 button and 2 text boxes.

Imports System.IO

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

'This Sub Saves to the file

    Dim myString As String
    Dim myFile As Integer

    myString = TextBox1.Text
    myFile = FreeFile()


    FileOpen(myFile, "C:\Steve.txt", OpenMode.Output)
    Print(myFile, myString)
    FileClose(myFile)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

'This Sub read the file

    Dim myFile As Integer
    Dim LinesFromFile, NextLine As String

    myFile = FreeFile()

    FileOpen(myFile, "C:\Steve.txt", OpenMode.Input)

    Do Until EOF(myFile)
        NextLine = LineInput(myFile)
        LinesFromFile = LinesFromFile & NextLine & Chr(13) & Chr(10)
    Loop

    TextBox2.Text = LinesFromFile

End Sub