HELP
My program is to read sequential file into a listbox. A Comma seperate each field in the record . There are 6 fields.
My problem is when the file is read, the records in the file are duplicated and part of the record appears on a different line when placed into the list box. Example of a record in the txt file: 1212,Albertson,William,R,10,04
When read to list box it should only put the 1st thru 4th fields.
CODE
Public Class galaxyTrekkers
' declare members structure
Structure Members
Public id As String
Public lName As String
Public fName As String
Public mInt As String
Public grade As String
Public classPeriod As String
End Structure
' declare array
Private member(250) As Members
Private Sub galaxyTrekkers_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' read file and determine if file exist
Dim text As String
Dim newLine As Integer
Dim recordIndex As Integer
Dim record As String
Dim commaIndex As Integer
If My.Computer.FileSystem.FileExists("StudentList.txt") Then
text = My.Computer.FileSystem.ReadAllText("StudentList.txt")
For subscript As Integer = 0 To 7
' locate new line
newLine = _
text.IndexOf(ControlChars.NewLine, recordIndex)
'assign a line
record = _
text.Substring(recordIndex, newLine - recordIndex)
' locate comma
commaIndex = text.IndexOf(",", 0)
' assign member to the array
member(subscript).id = record.Substring(0, commaIndex)
member(subscript).lName = record.Substring(commaIndex + 1)
member(subscript).fName = record.Substring(commaIndex + 1)
member(subscript).mInt = record.Substring(commaIndex + 1)
' add the member to the list box
ListBox1.Items.Add(member(subscript).id)
ListBox1.Items.Add(member(subscript).lName)
ListBox1.Items.Add(member(subscript).fName)
ListBox1.Items.Add(member(subscript).mInt)
' update the record index by 6
recordIndex = newLine + 6
Next
Else
MessageBox.Show("File does not exist", "List", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub