PDA

View Full Version : Select Case range of values



kenif
- 24th June 2009, 07:05
A case statement that allowed a range of values would be very helpful. As it is, I can't find any syntax that works (>5 AND <20, for instance, is a dud)

SELECT CASE var
CASE 27 TO 53
END SELECT

Is there a workaround, short of building a long CASE staircase?

sayzer
- 24th June 2009, 10:19
A <font color="#000080"><b>VAR BYTE




SELECT CASE </b></font>A


<font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000">5 </font><font color="#000080"><b>AND IS </b></font>&lt; <font color="#FF0000">20
</font><font color="#000080"><i>' do your stuff...
</i><b>CASE IS </b></font>&lt; <font color="#FF0000">40 </font><font color="#000080"><b>AND NOT </b></font><font color="#FF0000">35
</font><font color="#000080"><i>' do your stuff...
</i><b>END SELECT



</b></font>

Darrel Taylor
- 25th June 2009, 00:30
<font color="#000080"><b>CASE IS </b></font>&gt; <font color="#FF0000">5 </font><font color="#000080"><b>AND IS </b></font>&lt; <font color="#FF0000">20
</font>

That's what I thought too. &nbsp; But when I tried it in a test program, it didn't work.
It's not in the manual, even though it compiles without warnings. &nbsp; So I wasn't sure if it was valid.

I asked meLabs, and they said ...
"SELECT CASE isn't capable of logic in the cases. Never has been."



Is there a workaround, short of building a long CASE staircase?
I quess you'll need to use IF statements instead of SELECT CASE.


IF (A >= 5) AND (A <= 20) THEN
; something
ELSE
IF (A > 20) AND (A <= 40) THEN
; something else
ENDIF
ENDIF

Acetronics2
- 25th June 2009, 14:27
Hi,



A VAR BYTE

SELECT CASE A


CASE IS > 5 AND IS < 20
' do your stuff...
CASE IS < 40 AND NOT 35
' do your stuff...
END SELECT


could be Written





SELECT CASE A

CASE IS <= 5

CASE IS < 20
LCDOUT $FE,2, " < 20 " , DEC3 A

CASE 35

CASE IS < 40
LCDOUT $FE,2, " < 40 " , DEC3 A

CASE ELSE

END SELECT



CASE A left "blank" works fine...

Alain