I'm trying to add an Item to an Array 2d.
But this throws an exception with message like this: Redim only can change the dimension which is more to the right
' Create Array 2D
Dim MyArray As String(,) = _
{{"Item 0,0", "Item 0,1"}, {"Item 1,0", "Item 1,1"}, {"Item 2,0", "Item 2,1"}}
' Add Item
ReDim Preserve MyArray(MyArray.GetUpperBound(0)+1, MyArray.GetUpperBound(1)+1)
MyArray(MyArray.GetUpperBound(0), MyArray.GetUpperBound(1) - 1) = "Item 3,0"
MyArray(MyArray.GetUpperBound(0), MyArray.GetUpperBound(1)) = "Item 3,1"
What I'm doing wrong?
Also... I could set the two dimensions at the same time like this?:
ReDim Preserve MyArray(MyArray.GetUpperBound(0)+1, MyArray.GetUpperBound(1)+1)
MyArray(lastitem) = {"Item 3,0", "Item 3,1"}
UPDATE:
Well... trying it otherwise, I don't get it, the code does not work:
' Add Item
Dim MyArray2(MyArray.GetUpperBound(0) + 1, MyArray.GetUpperBound(1) + 1)(,) As String
MyArray.CopyTo(MyArray2, 0)
MyArray2(MyArray2.GetUpperBound(0), MyArray2.GetUpperBound(1) - 1) = "Item 3,0"
MyArray2(MyArray2.GetUpperBound(0), MyArray2.GetUpperBound(1)) = "Item 3,1"