This code works perfectly except when I start I get a message that file is not found. The file is there and everything reads perfectly. How can I get the file to read and not get the message that the file is not found? Do I need to use something other than Try? I tried taking the Try away and then I get errors and no file reads. Jo Ann
[CODE=vbnet]Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'load the item into the combobox
Try
vinStreamreader = New StreamReader("c ar.txt")
DisplayRecord()
Catch ex As Exception
'File is not found.
MessageBox.Show ("File does not exist.")
End Try
End Sub
Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
'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.Te xt = vinString
Me.ComboBox1.It ems.Add(ComboBo x1.Text)
Me.ListBox1.Ite ms.Add(vinStrea mreader.ReadLin e())
Me.ListBox2.Ite ms.Add(vinStrea mreader.ReadLin e())
Me.ListBox3.Ite ms.Add(vinStrea mreader.ReadLin e())
Loop
'Display labels
Me.Label4.Text = Me.ListBox1.Ite ms(Me.ComboBox1 .SelectedIndex)
Me.Label5.Text = Me.ListBox2.Ite ms(Me.ComboBox1 .SelectedIndex)
Me.Label6.Text = Me.ListBox3.Ite ms(Me.ComboBox1 .SelectedIndex)
End Sub
End Class[/CODE]
[CODE=vbnet]Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
'load the item into the combobox
Try
vinStreamreader = New StreamReader("c ar.txt")
DisplayRecord()
Catch ex As Exception
'File is not found.
MessageBox.Show ("File does not exist.")
End Try
End Sub
Private Sub ComboBox1_Selec tedIndexChanged (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles ComboBox1.Selec tedIndexChanged
'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.Te xt = vinString
Me.ComboBox1.It ems.Add(ComboBo x1.Text)
Me.ListBox1.Ite ms.Add(vinStrea mreader.ReadLin e())
Me.ListBox2.Ite ms.Add(vinStrea mreader.ReadLin e())
Me.ListBox3.Ite ms.Add(vinStrea mreader.ReadLin e())
Loop
'Display labels
Me.Label4.Text = Me.ListBox1.Ite ms(Me.ComboBox1 .SelectedIndex)
Me.Label5.Text = Me.ListBox2.Ite ms(Me.ComboBox1 .SelectedIndex)
Me.Label6.Text = Me.ListBox3.Ite ms(Me.ComboBox1 .SelectedIndex)
End Sub
End Class[/CODE]
Comment