Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug when redimensioning multi-dimension arrays?
#10
For illusttation, notice how things work out when I make both arrays lower limit 1, instead of 0:

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.
Reply


Messages In This Thread
RE: Bug when redimensioning multi-dimension arrays? - by SMcNeill - 06-20-2024, 03:40 PM



Users browsing this thread: 3 Guest(s)