'_________________________________________________________________________ 'U S I N G A S I M P L E S T R E A M R E A D E R & W R I T E R ' Ron Kessler ' 5/15/07 '_________________________________________________________________________ 'This program shows you how to read/write 4 lines of data from a text file. 'Note that I did not check to make sure they type something into the text boxes!!!! 'Make sure your code matches the order in which the data is created in the text file. Public Class frmMain Private Sub btnGet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGet.Click '---create a new StreamReader called myReader and tell it where the file is. You must use ..\..\ before ' the file name so VS will look in the correct place. Dim myReader As New System.IO.StreamReader("..\..\custData.txt") '---now read each line of the file and put the contents into the correct text box txtPIN.Text = Trim(myReader.ReadLine) txtLast.Text = Trim(myReader.ReadLine) txtFirst.Text = Trim(myReader.ReadLine) txtBalance.Text = Trim(myReader.ReadLine) myReader.Close() 'close the file End Sub Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim myWriter As New System.IO.StreamWriter("..\..\custData.txt", False) '---now write the contents of the text boxes back to the file, one line at a time myWriter.WriteLine(txtPIN.Text.Trim) myWriter.WriteLine(txtLast.Text.Trim) myWriter.WriteLine(txtFirst.Text.Trim) myWriter.WriteLine(txtBalance.Text.Trim) myWriter.Close() 'close the file End Sub Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click txtPIN.Clear() txtLast.Clear() txtFirst.Clear() txtBalance.Clear() End Sub Private Sub btnQuit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuit.Click Me.Close() End Sub End Class