06-20-2024, 05:08 PM
And I's brokes it already!
Which goes to show how complex an universal routine would be to write and toss into the core language. This is breaking now, when one array is smaller than the other.
You need to check for lbound on both, ubound on both, for all dimensions.... only copy the parts that overlap... and then expand that to work for any number of dimensions which someone might have in their array.
Code: (Select All)
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()
moreXPerRow Grid(), 4, 10
ShowArrayValues Grid()
END
SUB moreXPerRow (arr() AS LONG, xpr AS LONG, r 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 uby
c(x, y) = arr(x, y)
NEXT
NEXT
REDIM arr(xpr, r) ' 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
FOR x = lbx TO uby
arr(x, y) = c(x, y)
NEXT
NEXT
END SUB
SUB ShowArrayValues (arr() AS LONG)
PRINT "Array Values:": PRINT
FOR y = 1 TO UBOUND(arr, 2)
PRINT USING "Row ## "; y,
FOR x = 1 TO UBOUND(arr, 1)
PRINT USING " ##"; arr(x, y);
NEXT
PRINT
NEXT
PRINT
END SUB
Which goes to show how complex an universal routine would be to write and toss into the core language. This is breaking now, when one array is smaller than the other.
You need to check for lbound on both, ubound on both, for all dimensions.... only copy the parts that overlap... and then expand that to work for any number of dimensions which someone might have in their array.