06-19-2024, 08:49 PM
I have a program that changes the dimensions of a dynamic multidimensional array.
After the `REDIM _PRESERVE`, the array values are scrambled.
Here is some test code:
Am I misunderstanding something, or is this a bug? How can I make this work so that the initial values stay in their respective spots?
After the `REDIM _PRESERVE`, the array values are scrambled.
Code: (Select All)
Initial Array Values of array Test(5,5):
1 1 2 3 4 5
2 6 7 8 9 10
3 11 12 13 14 15
4 16 17 18 19 20
5 21 22 23 24 25
Array Values after REDIM _PRESERVE Test(10, 10):
1 0 23 20 0 0 0 0 0 0 0
2 2 0 25 0 0 0 0 0 0 0
3 7 4 0 0 0 0 0 0 0 0
4 12 9 0 0 0 0 0 0 0 0
5 17 14 0 0 0 0 0 0 0 0
6 22 19 0 0 0 0 0 0 0 0
7 0 24 0 0 0 0 0 0 0 0
8 3 0 0 0 0 0 0 0 0 0
9 8 5 0 0 0 0 0 0 0 0
10 13 10 0 0 0 0 0 0 0 0
Code: (Select All)
REDIM SHARED Grid(5, 5)
' LoadInitialValues
FOR y = 1 TO 5
FOR x = 1 TO 5
counter = counter + 1
Grid(y, x) = counter
NEXT
NEXT
ShowArrayValues
REDIM _PRESERVE Grid(10, 10)
ShowArrayValues
END
SUB ShowArrayValues
PRINT "Array Values:": PRINT
FOR y = 1 TO UBOUND(Grid, 1)
PRINT USING "Row ## "; y,
FOR x = 1 TO UBOUND(Grid, 2)
PRINT USING " ##"; Grid(y, x);
NEXT
PRINT
NEXT
PRINT
END SUB
Am I misunderstanding something, or is this a bug? How can I make this work so that the initial values stay in their respective spots?