Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 06:26 07 Apr 2026 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Change / Create ARRAY size in SUB / FUNCTION

Author Message
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 99
Posted: 01:08pm 06 Apr 2026
Copy link to clipboard 
Print this post

Is it possible to change the array size that it returned or referenced in a SUB or FUNCTION?

I would like to have a FUNCTION or SUB that queries a data file looking for 0 or more matches and returns (somehow) an array with the found matches.

I've only come up with two solutions thus far. Neither is as ideal / clean as I would like.

1) Use a global array and use REDIM in the function.

2) Split the lookup logic such that it first returns the number of matches. The calling code then creates an array of the appropriate size and passes that to the second part of the lookup routine that populates that array.


Thanks,
Mark
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3730
Posted: 02:49pm 06 Apr 2026
Copy link to clipboard 
Print this post

What's your objection to "1) Use a global array and use REDIM in the function."

I use that extensively in PicoDB, especially REDIM PRESERVE on an array of structure elements before using STRUCT SORT in order to reduce the sort to the not-fixed number of elements (for instance, results of a query).
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on FOTS
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 8733
Posted: 03:06pm 06 Apr 2026
Copy link to clipboard 
Print this post

Don't you save heap by using a global array?
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
Mark
Regular Member

Joined: 26/11/2022
Location: United States
Posts: 99
Posted: 06:36pm 06 Apr 2026
Copy link to clipboard 
Print this post

Rethinking the use cases, the global array should work.

Thanks,
Mark
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2026