Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Day 026: ERASE
#11
(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 ?
Do you have an example of what you are trying to do?
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#12
(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
Reply
#13
Sounds like you are trying to use an array dimed in main code in a private sub then you have to say Dim Shared so subs can see it too or pass it in parameters list when calling subroutine.

10 is the allowed maximum for an array not Dimensioned.

Also Erase works for static Dim arrays not for Dynamic ReDim arrays.

That wacked me out when I first started with QB64, why won't a Dim array ReDim? (because it is static because I used Dim I'm stuck with one size)
or how do your clear a Dim array? (ERASE !!!)
b = b + ...
Reply




Users browsing this thread: 1 Guest(s)