Hi,
I've got a problem with my listbox here. Here's my current code
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
ListBox2.Items().Clear()
Dim Pancake As String
ListBox1.GetItemText(Pancake)
Dim ing As String
Dim sr As IO.StreamReader
sr = File.OpenText("D:My DocumentsVisualStudiosExerciseWeek2Pancakes.txt")
If Not File.Exists("D:My DocumentsVisualStudiosExerciseWeek2Pancakes.txt") Then
MessageBox.Show("File does not exist", "My_Application", MessageBoxButtons.OK)
Return
End If
ing = sr.ReadLine()
'ListBox2.Items.Add(ing)
While Not (ing Is Nothing)
'ing = ing.Trim()
'If ing.Length > 0 Then
'ing = sr.ReadLine()
ListBox2.Items.Add(ing)
'End If
End While
End Sub
End Class
There are two list boxes here. in listbox1 consist of
sponge
pancake
Lamington
when i double click on pancake it supposed to read a file called pancake.txt which is consist of
eggs
flour
butter
milk
and display it in second listbox called listbox2
But when i run it and double click it causes program to crash. I suspect it is because of the wrong while loop. anyone can help me??