06-10-2023, 06:35 PM
(06-10-2023, 06:28 PM)sivacc Wrote: Hi , I 'm new here . But have persisting problem ..I want to dim an array, or redim it in a sub and pass values through sub's parameter list . I get the dim bounds reading a file ( in the sub) It wont compile. When I print the ubound before redim , I get 10, default size in BASIC it seems. Breaking the sub, declaring arrays in the main is so awkward. Loads of thanks for a tip or clue ?
You'll want to REDIM the array in the main module, and then resize it as needed in the SUB/FUNCTION. A quick example is below for you:
Code: (Select All)
ReDim ResizeableArray(10) As Long
Print "Before running our SUB, our array holds"; UBound(ResizeableArray); "Elements."
ExampleResize ResizeableArray()
Print "After running our SUB, our array holds"; UBound(ResizeableArray); "Elements."
Sub ExampleResize (Array() As Long)
Print "Entering the SUB"
Print "The original size of this array holds"; UBound(Array); "elements."
ReDim Array(20) As Long
Print "The resized size of this array holds"; UBound(Array); "elements."
Print "Exiting the SUB"
End Sub