Announce and discuss the progress of your various programming-related projects...programs, games, websites, tutorials, libraries...anything!
Moderators: Pete, Mods
-
mikefromca
- Coder
- Posts: 25
- Joined: Wed Oct 16, 2019 11:28 am
Post
by mikefromca » Tue Jan 05, 2021 12:59 am
I have confirmed this on two instances that
an incorrect value is returned each time in both Qbasic 1.1 and QuickBasic 4.0. The code is this:
Code: Select all
DIM SHARED v as STRING * 100
PRINT LEN(want$) 'Prints 100 instead of 3!!!
FUNCTION want$
v$="123"
want$=v$
END FUNCTION
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.
-
MikeHawk
- Coder
- Posts: 36
- Joined: Sun Jul 08, 2018 11:23 am
Post
by MikeHawk » Tue Jan 05, 2021 10:47 am
Fairly certain it's working as intended. Fixed-length strings will always return the same length, regardless of their content.
Code: Select all
DIM v AS STRING * 50
v = "Fifty"
PRINT "*";STRING$(50, "-");"*"
PRINT "*";v;"*"
Consider the following:
Code: Select all
DECLARE FUNCTION var% (variable%)
DIM SHARED dummy AS INTEGER
dummy = 50
PRINT var%(10)
FUNCTION var% (variable%)
var% = variable% + dummy%
END FUNCTION
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...)