I am trying to get each item in a list box into a string array. However, I keep getting an index error and I am not sure why. I am doing this so i can perform a LINQ on the array. Here is the error and the code in question. Thank you for any help in advance.
Error:
InvalidArgument=Value of ’16’ is not valid for ‘index’.
Parameter name: index
Code:
Dim size As Integer = lstBoxSeats.Items.Count()
Dim seats(size) As String
For i = 0 To size
seats(i) = lstBoxSeats.Items(i).ToString()
Next
Your array is zero based, the count is actual number of items. You need to subtract 1 from the count for your index.
i.e.
Correction: just realized that you were using count to dimension your seats array which is leaving a empty position in your seats array