07-17-2024, 09:24 PM
(07-17-2024, 08:12 PM)Kernelpanic Wrote: There are problems here, but why? Personally, I think it is wrong to declare an array with ReDim... that is confusing. For me, the clear line is lost.I think you're getting too caught up in the name `ReDim`, it's potentially a badly chosen command name. `ReDim` does not pair with `Dim`, you can't use `Dim` initially and then use `ReDim` afterwards. Rather, `Dim` and `ReDim` declare different types of arrays, static vs. dynamic. Only dynamic arrays declared using `ReDim` can be subsequently resized by another `ReDim`.
This detail is mentioned on the Wiki page for `ReDim`, though it's about halfway down:
Quote:REDIM cannot change $STATIC arrays created with a DIM statement unless the $DYNAMIC Metacommand is used!(Note that it does work like you're thinking if you use `$Dynamic`, but IMO you should forget that exists and just use `ReDim`)
To create a dynamic array use the $DYNAMIC metacommand or use REDIM rather than DIM when first creating the array.