06-20-2024, 03:40 PM
For illusttation, notice how things work out when I make both arrays lower limit 1, instead of 0:
REDIM PRESERVE does nothing more than preserve the memory and then move the whole block from the old array to the new array. If you change more than the RIGHTMOST index, the structure won't read the same and your data will seem as if it's been "scrambled". Effictively, all you can do is REDIM and PRESERVE that rightmost index -- if you need more, then you'll have to write your own routine to handle that.
Code: (Select All)
REDIM SHARED Grid(1 TO 5, 1 TO 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(1 TO 10, 1 TO 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
REDIM PRESERVE does nothing more than preserve the memory and then move the whole block from the old array to the new array. If you change more than the RIGHTMOST index, the structure won't read the same and your data will seem as if it's been "scrambled". Effictively, all you can do is REDIM and PRESERVE that rightmost index -- if you need more, then you'll have to write your own routine to handle that.