Shop OBEX P1 Docs P2 Docs Learn Events
PBASIC BS2p - SELECTCASE - CASE using AND,OR — Parallax Forums

PBASIC BS2p - SELECTCASE - CASE using AND,OR

John KauffmanJohn Kauffman Posts: 653
edited 2011-02-04 13:12 in BASIC Stamp
I could not find in the Pbasic help an example of using CASE with AND & OR.
In the fora I found http://forums.parallax.com/newthread.php?do=newthread&f=48
I think I am doing the same, but at the AND I get an error
" expect binary operator or ')' "

My code follows. It look ling, but is a lot of comments and it is all simple:

<code>
' Examples of code for control structures

' {$STAMP BS2p}
' {$PBASIC 2.5}

' For these examples we will use a variable which is temperature
' Since we don't have a temp sensor hooked up
' we will just enter the temp value from the PC using DEBUGIN
' the temperature should be 100C

ledRed PIN 12 ' temp is too high
ledGreen PIN 11 ' temp is in OK = 100C
ledYellow PIN 10 ' temp is low

bytTemperature VAR Byte
CounterFlashes VAR Nib


'
SELECT CASE EXAMPLE
' note we have five possibilities:
' if temp is 100 green is on
' if temp is 100 to 150 red is on
' if temp is over 150 red flashes three times
' if temp is under 100 yellow is on
' if temp is under 50 yellow flashes thre times

DO
DEBUGIN DEC bytTemperature

SELECT bytTemperature
CASE =100 ' temp is OK
LOW ledRed
HIGH ledGreen
LOW ledYellow
' ******************* won't compile on next line
CASE <100 AND >=50 ' temp is low also fails: CASE (<100 AND >=50)
LOW ledRed
LOW ledGreen
HIGH ledYellow
CASE <50 ' temp is very low
LOW ledRed
LOW ledGreen
FOR CounterFlashes = 0 TO 2
HIGH ledYellow
PAUSE 500
LOW ledYellow
PAUSE 500
HIGH ledyellow
NEXT
CASE >100 AND <=150 ' temp is high
HIGH ledRed
LOW ledGreen
LOW ledYellow
CASE >150 ' temp is very high
FOR CounterFlashes = 0 TO 2
HIGH ledRed
PAUSE 500
LOW ledRed
PAUSE 500
HIGH ledRed
NEXT
LOW ledGreen
LOW ledYellow
ENDSELECT
LOOP

</code>

Comments

  • davejamesdavejames Posts: 4,047
    edited 2011-02-03 14:59
    John,

    I'm looking at the SELECT...CASE chapter in the Syntax and Reference book v2.2 (page 387) and there's a comment that says "Conditional logic operators not allowed." Then there's words that discuss using commas to separate conditions resulting in logical operations.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2011-02-03 15:01
    Use CASE 50 TO 99

    -Phil
  • John KauffmanJohn Kauffman Posts: 653
    edited 2011-02-03 15:39
    Dave: Interesting find. I was basing my expectation on the "Quick Facts" table in the pbasic help, selectcase. It says "Conditional logic operators... AND, OR"
    Phil: worked, thanks.
  • davejamesdavejames Posts: 4,047
    edited 2011-02-04 13:12
    Hi John,

    Hmmmmm - you're right.

    I immediately reach for the reference book rather than "start-the-computer, open-parallax-help"........and there is a difference between the two sources of information.

    I tried an experiment with SELECT/CASE (see attached image) and received the same error message as you. However, when implementing the same conditions with an IF/THEN, no error was generated. :surprise:

    Maybe a Forum expert can shed light on this.

    Regards,

    DJ
    399 x 535 - 17K
Sign In or Register to comment.