DIM SHARED v as STRING * 100
PRINT LEN(want$) 'Prints 100 instead of 3!!!
To make this bug happen, the variable name being set for the return value of the function (excluding dollar sign) must be the same as the one declared as a shared fixed string in the mainline program. In this case, I used v.
If shared is removed from DIM then the correct answer is returned.
I have not tested this on QuickBasic 4.5 or later.
DECLARE FUNCTION var% (variable%)
DIM SHARED dummy AS INTEGER
dummy = 50
FUNCTION var% (variable%)
var% = variable% + dummy%
You expected QB to make a difference between v (an explicitly defined, shared fixed-length string) and v$ (an implicit, local, variable-length string)? The shared variable has precedent. You could RTRIM it before obtaining the length (but then, you'd get the length of the temporary string created by RTRIM...)