Number of downloads: 10im also going to attach the Program with this so if any wants to look at it can.
' when this code executes on the exit form click event it is supposed to write the entire collection to a txtfile 'it writes the first file for every item in the collection. I've been hacking away at for about 3 weeks. Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click Dim sDatafile As StreamWriter Try 'open the file sDatafile = File.AppendText("StudentData.txt") For Each student As Student In studentCollection 'write student data to the file. sDatafile.WriteLine(student.LastName) sDatafile.WriteLine(student.FirstName) sDatafile.WriteLine(student.IdNumber) sDatafile.WriteLine(student.TestAverage) sDatafile.WriteLine(student.Grade) Next sDatafile.Close() Catch ex As Exception MessageBox.Show(ex.Message) End Try Me.Close() End Sub 'Reads the student collection in StudentData.txt file when the form loads 'It will place all data in the correct labels and list box. on the main form.[/color] Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim objStudent As New Student Dim StudentFile As StreamReader StudentFile = File.OpenText("studentData.txt") Do Until StudentFile.Peek = -1 objStudent.LastName = StudentFile.ReadLine objStudent.FirstName = StudentFile.ReadLine objStudent.IdNumber = StudentFile.ReadLine objStudent.TestAverage = CDbl(StudentFile.ReadLine) StudentFile.ReadLine() AddRecord(objStudent) Loop UpdateListBox() End Sub