Syntax / sanity check
BS2p...
Using IF, I can use a compound AND condition·such as;
But can the same be done with Select Case? (I get error messages with various iterations using AND, or colon etc)
From the help file (yes I read it)...
···SELECT Expression
· · ·CASE Condition(s)
Statement(s) is any valid PBASIC statement or statements. Multiple statements may be placed on the same line (though not recommended) by separating each statement with a colon ( : ).
Bottom line...Can an AND condition be used with CASE, and if so, the proper syntax is?
Using IF, I can use a compound AND condition·such as;
IF gear >90 THEN FIRST IF (gear > 50) AND (gear < 91) THEN SECOND IF (gear > 35) AND (gear < 51) THEN THIRD IF (gear > 14) AND (gear < 36) THEN FOURTH
But can the same be done with Select Case? (I get error messages with various iterations using AND, or colon etc)
SELECT gear CASE > 90 'some code CASE (> 50 ) AND (< 91 ) 'some other code 'etc, etc ENDSELECT
SELECT gear CASE > 90 'some code CASE (gear > 50 ) AND ( gear < 91 ) 'some other code 'etc, etc ENDSELECT
From the help file (yes I read it)...
···SELECT Expression
· · ·CASE Condition(s)
Statement(s) is any valid PBASIC statement or statements. Multiple statements may be placed on the same line (though not recommended) by separating each statement with a colon ( : ).
Bottom line...Can an AND condition be used with CASE, and if so, the proper syntax is?
Comments
· SELECT gear
·· ·CASE·> 90
··· · ' first
··· CASE 51 TO 90
···· ·' second
·· ·CASE 36 TO 50
···· ·' third
· · CASE 15 TO 35
··· · ' fourth
· · CASE ELSE
··· · ' bad value
· ENDSELECT
Another way to do the range thing -- that more closely matches your IF-THEN construct -- is like this:
· SELECT gear
·· ·CASE·> 90
··· · ' first
··· CASE·> 50, < 91
······' second
·· ·CASE > 35, < 51
······' third
· · CASE > 14, < 36
····· ' fourth
· · CASE ELSE
··· · ' bad value
· ENDSELECT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon Williams
Applications Engineer, Parallax
Dallas, TX· USA
·P.S. Did I miss the solution in the help file? I thought I read it carefully.
I am using V2.2
Post Edited (KenM) : 5/10/2005 1:43:35 PM GMT
·· Yep, it was there...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com