07-22-2024, 04:15 PM
(07-22-2024, 03:22 PM)DSMan195276 Wrote:(07-22-2024, 02:34 PM)Kernelpanic Wrote:(07-18-2024, 07:51 PM)Pete Wrote: Cool, This is a good point, and something I can't quite off-hand come up with a reason why a variable can be used to avoid a numerically assigned array duplicate definition error...I don't understand what you're trying to say. It's clear that ReDim y(7) produces an error. Dim y(5) doesn't specify a constant value.
That's how it works.
Pete's point is a good catch, which is that the `ReDim x(b)` line should produce the same error as the `ReDim y(7)` line. I assume it's just a bug, though I guess the QBasic behavior should be checked before saying that for sure.
Usage of a variable for the bounds is different from a constant because the array has to be allocated/initialized at the position of the `Dim` statement, rather than at the start of the program or SUB/FUNCTION. This is similar to how `ReDim` works, the allocation takes place at the point of the `ReDim`, and it seems like the flag indicating the array is static never gets set when allocated this way. If the flag is missing then you're allowed to do a `ReDim`, so you don't get an error.
It might have been left that way to remain compatiple to old QB, the inconsistency sure is confusing.
b = b + ...