06-20-2024, 06:43 PM
Typo here: For x = lbx To uby
Change to: For x = lbx To ubx
Change to: For x = lbx To ubx
Code: (Select All)
'Expanded upon by Steve-the-AMAZING(tm) from what bplus had originally
REDIM Grid(1 TO 5, 1 TO 5) AS LONG
' LoadInitialValues
FOR y = 1 TO 5
FOR x = 1 TO 5
counter = counter + 1
Grid(x, y) = counter
NEXT
NEXT
ShowArrayValues Grid()
Redim2D Grid(), 0, 6, 3, 4
ShowArrayValues Grid()
Redim2D Grid(), 1, 5, 1, 5
ShowArrayValues Grid()
END
SUB Redim2D (arr() AS LONG, xlb AS LONG, xub, ylb AS LONG, yub AS LONG) ' xpr x per row
DIM AS LONG lbx, lby, ubx, uby
lbx = LBOUND(arr, 1)
lby = LBOUND(arr, 2)
ubx = UBOUND(arr, 1)
uby = UBOUND(arr, 2)
DIM c(lbx TO ubx, lby TO uby) AS LONG
FOR y = lby TO uby
FOR x = lbx TO ubx
c(x, y) = arr(x, y)
NEXT
NEXT
REDIM arr(xlb TO xub, ylb TO yub) ' fixed
'ReDim _Preserve arr(xpr, r) 'nope
'ReDim _Preserve arr(lbx To xpr, lby To r)
'ReDim _Preserve arr(lbx To xpr, lby To r) As Long ' nope
FOR y = lby TO uby
IF y >= ylb AND y <= yub THEN
FOR x = lbx TO ubx
IF x >= xlb AND x <= xub THEN arr(x, y) = c(x, y)
NEXT
END IF
NEXT
END SUB
SUB ShowArrayValues (arr() AS LONG)
PRINT "Array Values:": PRINT
FOR y = LBOUND(arr, 2) TO UBOUND(arr, 2)
PRINT USING "Row ## "; y,
FOR x = LBOUND(arr, 1) TO UBOUND(arr, 1)
PRINT USING " ##"; arr(x, y);
NEXT
PRINT
NEXT
PRINT
END SUB