QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: daro on May 17, 2021, 08:51:48 am
-
I'm finding this strange error when using a constant inside of a select case, any ideas why?
I've tried many different ways but it seems to be the use of a CONST inside of the SELECT CASE giving the error.
Expected string expression on line 12
Caused by (or after) CASE "A", 1 , "a",1 , KEY_ARROW_LEFT
Case "A", "a", KEY_ARROW_LEFT
Case "W", "w", KEY_ARROW_UP
Case "D", "d" , KEY_ARROW_RIGHT
Case "S", "s", KEY_ARROW_DOWN
Case "Z", "z", KEY_PAGE_DOWN
Case "X","x", KEY_PAGE_UP
-
@daro Looks indeed like a bug. We'll have a look.
In the meantime, make those DIM SHARED AS STRING instead of CONSTs, for the same expected effect:
DIM SHARED AS STRING KEY_ARROW_LEFT
, KEY_ARROW_UP
, KEY_ARROW_RIGHT
, KEY_ARROW_DOWN
, KEY_PAGE_UP
, KEY_PAGE_DOWN
Welcome aboard.
-
I would recommend using _KEYHIT or _KEYDOWN over INKEY$ and changing that SELECT CASE into IF THENs.
@FellippeHeitor
Doesn't CONST have issues when using variables as assignments?
Wasn't there something not that long ago about using a variable to assign constant?
something like:
A%=15-3
CONST VALUE = A%
I can't quite remember now. not having any luck with the search either, but I could swear we've had something like this before.
-
I would recommend using _KEYHIT or _KEYDOWN over INKEY$ and changing that SELECT CASE into IF THENs.
@FellippeHeitor
Doesn't CONST have issues when using variables as assignments?
Wasn't there something not that long ago about using a variable to assign constant?
something like:
A%=15-3
CONST VALUE = A%
I can't quite remember now. not having any luck with the search either, but I could swear we've had something like this before.
We've had trouble using Functions and doing math but I think it's been fixed. Maybe not all string stuff is, I think we are using Steve Math Evaluator?
-
Turns out the CONST evaluator was never meant to be used with string functions, like Chr$, Space$, etc. - but Chr$ had been left there as valid - just a slip. The latest dev build generated today fixes that by not allowing string functions in CONSTs. This is a list of the functions that can be used in CONSTs. The wiki page for CONST is getting updated too.
_SECH, _CSCH, _COTH, COS, SIN, TAN, LOG, EXP, ATN, _D2R, _D2G, _R2D, _R2G, _G2D, _G2R, ABS, SGN, INT, _ROUND, _CEIL,
-
I would recommend using _KEYHIT or _KEYDOWN over INKEY$ and changing that SELECT CASE into IF THENs.
@FellippeHeitor
Doesn't CONST have issues when using variables as assignments?
Wasn't there something not that long ago about using a variable to assign constant?
something like:
A%=15-3
CONST VALUE = A%
I can't quite remember now. not having any luck with the search either, but I could swear we've had something like this before.
It was never really allowed with variables, but we did have a problem recently (fixed in 1.5) that would cause issues when referencing existing CONSTs in a new CONST assignment.
-
edit: OP wanted strings not numbers