Here is the code again and the error I get is Invalid Argument=Value of "-1" is not valid for 'index' Parameter Name:index
Please advise the code so this error goes away and the program will still execute correctly. Other suggestions posted either still give errors or the program does not execute once I put the suggestion in. Thanks for your help.
Jo Ann
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'load the item into the combobox
Try
vinStreamreader = New StreamReader("car.txt")
DisplayRecord()
Catch ex As Exception
'File is not found.
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
'Read the next record.
DisplayRecord()
End Sub
Private Sub DisplayRecord()
'Read and display the next record.
Dim vinString As String
Do While vinStreamreader.Peek <> -1
vinString = vinStreamreader.ReadLine()
Me.ComboBox1.Text = vinString
Me.ComboBox1.Items.Add(ComboBox1.Text)
Me.ListBox1.Items.Add(vinStreamreader.ReadLine())
Me.ListBox2.Items.Add(vinStreamreader.ReadLine())
Me.ListBox3.Items.Add(vinStreamreader.ReadLine())
Loop
'Display labels
Me.Label4.Text = Me.ListBox1.Items(Me.ComboBox1.SelectedIndex)
Me.Label5.Text = Me.ListBox2.Items(Me.ComboBox1.SelectedIndex)
Me.Label6.Text = Me.ListBox3.Items(Me.ComboBox1.SelectedIndex)
End Sub
End Class