06-21-2024, 07:19 PM
(06-20-2024, 10:57 PM)Kernelpanic Wrote: The manual for Quick- and QBasic: "Neither the type nor the dimension of an array may be changed."Quite right, QBasic and QuickBasic were much more limited than even PDS/QBX were, which allowed the size of dimensions to be changed: "Although you can change the size of an array's dimensions with the REDIM statement, you can not change the number of dimensions." (Microsoft BASIC Professional Development System 7.1 — Basic Language Reference, 1989, p. 289).
I don't know what you're doing, but I don't think it's solid.
Quote:When reducing an array dimension, DATA LOSS OCCURS.Well, what do you know! If I reduce a 5X5 array to 4X4, data is lost... Thanks!
Let's see where this ends up!
So many languages have the ability to change array dimensions, like python's del statement, javascript's slice method, the Arrays.copyOf method in Java, or std::vector's resize method in C++. It's too bad Q[uick]Basic didn't have something. I think the _PRESERVE keyword is a credit to the QB64 developers for including it.
I suppose that warning was a bit obvious, It's a long-ingrained habit of mine to ensure that any potential loss of data is fully documented so that anyone who reuses my code would have a full grasp of the consequences.
So here's what I'm doing...this code is part of a game with multiple levels that are loaded from user-editable text files. The dimensions of the maps are not known until read, and rather than read through the file twice (first a parsing read, then array dimensioning, then a loading read), I opted to use a more adaptive approach which adjusts the array size as it loads.
When all is done, the array is sometimes larger than required, so I reduce it. While it's not intended to pare down existing data from an array, you could use it for that, so I think the warning is warranted.