SELECT CASE string comparison problems
Posted: Fri Sep 30, 2022 11:36 pm
SELECT CASE has problems when comparing string characters.
CASE single variable comparisons work ok, eg: CASE "B".
But multiple variable comparisons (using TO or commas) cause error, eg :CASE "A" TO "F" or CASE "B","D"
Its the same for Annex and Annex32, and appears to be a SELECT CASE logic problem.
The following snippet demonstrates that numeric vars work as expected but string vars cause errors.
(the line IF "A" > "B"... just shows that string characters can actually be compared ok, presumably by ascii value)
'Select Case number vars work as expected
for c = 1 to 6
select case c
case 2: wlog str$(c) + ", 2"
case 4,3,6: wlog str$(c) + ", 3 or 4 or 6"
case 1 to 5: wlog str$(c) + ", 1 to 9"
case else: wlog str$(c) + ", else"
end select
next c
wlog ""
if "A" > "B" then wlog "A>B" else wlog "A<B" 'proves that character precedence can be prioritised
wlog ""
'Select Case string vars partialy work, but always errors with multiple vars, eg: when using commas or TO
for c = 1 to 6
c$ = str$(c)
select case c$
case "2": wlog str$(c) + ", 2"
case "4","3"', "6" 'works ok for one var (not necessarilly the 1st), but errors when another var is processed
wlog str$(c) + ", 4 or 3 or 6"
' case "a" to "h": wlog str$(c) + ",a to h" ' causes error if uncommented
case else: wlog str$(c) + ", else"
end select
next c
end
CASE single variable comparisons work ok, eg: CASE "B".
But multiple variable comparisons (using TO or commas) cause error, eg :CASE "A" TO "F" or CASE "B","D"
Its the same for Annex and Annex32, and appears to be a SELECT CASE logic problem.
The following snippet demonstrates that numeric vars work as expected but string vars cause errors.
(the line IF "A" > "B"... just shows that string characters can actually be compared ok, presumably by ascii value)
'Select Case number vars work as expected
for c = 1 to 6
select case c
case 2: wlog str$(c) + ", 2"
case 4,3,6: wlog str$(c) + ", 3 or 4 or 6"
case 1 to 5: wlog str$(c) + ", 1 to 9"
case else: wlog str$(c) + ", else"
end select
next c
wlog ""
if "A" > "B" then wlog "A>B" else wlog "A<B" 'proves that character precedence can be prioritised
wlog ""
'Select Case string vars partialy work, but always errors with multiple vars, eg: when using commas or TO
for c = 1 to 6
c$ = str$(c)
select case c$
case "2": wlog str$(c) + ", 2"
case "4","3"', "6" 'works ok for one var (not necessarilly the 1st), but errors when another var is processed
wlog str$(c) + ", 4 or 3 or 6"
' case "a" to "h": wlog str$(c) + ",a to h" ' causes error if uncommented
case else: wlog str$(c) + ", else"
end select
next c
end