|
Forum Index : Microcontroller and PC projects : Change / Create ARRAY size in SUB / FUNCTION
| Author | Message | ||||
| Mark Regular Member Joined: 26/11/2022 Location: United StatesPosts: 99 |
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 StatesPosts: 3730 |
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 KingdomPosts: 8733 |
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 StatesPosts: 99 |
Rethinking the use cases, the global array should work. Thanks, Mark |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |