Here is your example.
Since you are a student am I doing the homework? (Kidding...)
Private Sub subSaveToFile(ByVal strName As String, ByVal strPhone As String)
'* Pass your the data from your textboxes as parameters.
'* Create StreamWriter objects that will open and write to text files.
'* One for each file...
Dim streamWriterNames As System.IO.StreamWriter = System.IO.File.AppendText("C:\Names.txt")
Dim streamWriterPhones As System.IO.StreamWriter = System.IO.File.AppendText("C:\Phones.txt")
'* Write the Name to a text file and then close.
streamWriterNames.WriteLine(strName)
streamWriterNames.Close()
'* Write the Phone Number to a text file and then close.
streamWriterPhones.WriteLine(strPhone)
streamWriterPhones.Close()
End Sub
Private Sub subReadFiles()
'* This will read from each text file and populate
'* the listboxes.
'* Here are your Arrays
Dim arrNames As New ArrayList
Dim arrPhones As New ArrayList
'* Create StreamReader objects that will open and read from your text files.
'* One for each file...
Dim streamReaderNames As System.IO.StreamReader = System.IO.File.OpenText("C:\Names.txt")
Dim streamReaderPhones As System.IO.StreamReader = System.IO.File.OpenText("C:\Phones.txt")
'* Your list boxes for this example are:
'* lstName and lstPhone
'* Clear the contents of the lstName listbox
lstName.Items.Clear()
'* Read the Names.txt file
With streamReaderNames
While Not .EndOfStream
arrNames.Add(.ReadLine)
End While
'* Close the file.
.Close()
End With
'* Add the contents of the Name array to the name listbox
For intX As Integer = 0 To arrNames.Count - 1
lstName.Items.Add(arrNames.Item(intX))
Next
'* Highlight the first name
If lstName.Items.Count > 0 Then lstName.SelectedIndex = 0
'* Clear the contents of the lstPhone listbox
lstPhone.Items.Clear()
'* Read the Phones.txt file
With streamReaderPhones
While Not .EndOfStream
arrPhones.Add(.ReadLine)
End While
'* Close the file.
.Close()
End With
'* Add the contents of the Phone array to the Phone listbox
For intX As Integer = 0 To arrPhones.Count - 1
lstPhone.Items.Add(arrPhones.Item(intX))
Next
'* Highlight the first phone number
If lstPhone.Items.Count > 0 Then lstPhone.SelectedIndex = 0
End Sub
Best Regards,
Earl Francis