I am beginner in VB. I am trying to find the indexes of selected values of ListBox1 and print those indexes in ListBox2. I am not specifying the length of array. I want it to take the values dynamically. Here is the code..
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim a() As Integer
Dim b As Integer = 0
For x As Integer = 0 To ListBox1.Items.Count - 1
If ListBox1.GetSelected(x) = True Then
a(b) = x
b = b + 1
End If
Next
For x As Integer = 0 To a.Length - 1
ListBox2.Items.Add(a(x))
Next
End Sub
The exception I am getting at line a(b) = x
is as follows
NullReferenceException was unhandled
Object reference not set to an instance of an object.
Can you kindly help me in this?