I have created a 2 lists where one list is populated from the objects of the other list. As I transfer the details from the second list to an array and then analyze them I am getting an error. I can't seem to understand where the error is.
So I assume the issue lies with the array initialization and conversion of the array while comparison.
coa = ""
For i = 0 To partab.ListBox2.ListCount - 1
If partab.ListBox2.Selected(i) Then
If coa = "" Then
coa = partab.ListBox2.List(i).tostring()
Else
coa = coa & "," & partab.ListBox2.List(i).tostring()
End If
End If
Next i
Dim arr() As String
Dim arrv() As Integer
arr = Split(coa, ",")
For i = 0 To partab.ListBox2.ListCount - 1
If IsEmpty(arr) = True Then
arrv(0) = 99
Else
If arr(i) = "Vehicle-Vehicle" Then
arrv(i) = 1
ElseIf arr(i) = "Vehicle-Pedestrian" Then
arrv(i) = 2
ElseIf arr(i) = "Vehicle-Bicycle/Others" Then
arrv(i) = 3
ElseIf arr(i) = "Vehicle-Animal" Then
arrv(i) = 4
Else
arrv(i) = 99
End If
End If
Next i
Dim displayar As String
displayar = ""
If IsEmpty(arrv) Then
displayar = 99
Else
For i = 0 To partab.ListBox2.ListCount - 1
displayar = displayar & "," & arrv(i)
Next i
End If
So the code assumed the value of variable coa as empty and then accepts the value from the listbox2. The values are separated by a comma and stored in a string. The string is then converted to an array.
The array elements are compared to the string values as shown and another array with corresponding codes store the values. The second array is the one that is being for my analysis.
I am not sure where the code is wrong.
arr(i)has no itemi. You exceeded the maximum index ofarr..tostring()?? VBA or VB.Net?