Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug when redimensioning multi-dimension arrays?
#14
oK redim wont let me change the array ???

Code: (Select All)
Dim 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(), 10, 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)  'nope
    '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
b = b + ...
Reply


Messages In This Thread
RE: Bug when redimensioning multi-dimension arrays? - by bplus - 06-20-2024, 04:58 PM



Users browsing this thread: 1 Guest(s)