I am trying to increase the x value of the 2 dimensional array but I keep receiving this error.
'ReDim' can only change the rightmost dimension
I need to do this while maintaining the data of the array. Here is my code.
Dim x As Integer = 0
Dim y As Integer = 0
While reader.Read()
ReDim Preserve catagoryInfo(x, 2)
catagoryInfo(x, y) = reader.GetString(0)
y += 1
catagoryInfo(x, y) = reader.GetString(1)
x += 1
y = 0
End While
In a multidimensional array, you can change only the last dimension when you use Preserve. If you attempt to change any of the other dimensions, a run-time error occurs.
A part from this your code is really suboptimal because you are planning to Redim you array at every loop. Redimming with preserve is worse because not only the runtime allocates a new array but it should also copy from the old array to the new array.
In your case is better to declare a simple class like this
then use a List(Of CategoryInfo)
Now, if you really need to have your data inside a string array you could write
this is still not very optimal because you loop two times on your data but, at least, it will get your data as you want.