SELECT CASE string comparison problems

Here we can discuss about the problem found
Post Reply
User avatar
Electroguard
Posts: 836
Joined: Mon Feb 08, 2021 6:22 pm
Has thanked: 268 times
Been thanked: 317 times

SELECT CASE string comparison problems

Post by Electroguard »

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
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: SELECT CASE string comparison problems

Post by cicciocb »

Hi Robin,
thanks for reporting the issue.

This is not really a bug as the select case was intended to cover the numerical so the string arguments are not fully covered.
Anyway, your remark is valid and suggests some improvements for next releases
Post Reply