Select Case range of values


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2005
    Location
    Cocoa, Florida
    Posts
    42

    Default Select Case range of values

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Code:
    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>
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    <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."


    Quote Originally Posted by kenif
    Is there a workaround, short of building a long CASE staircase?
    I quess you'll need to use IF statements instead of SELECT CASE.
    Code:
    IF (A >= 5) AND (A <= 20) THEN
        ; something
    ELSE
        IF (A > 20) AND (A <= 40) THEN
             ; something else
        ENDIF
    ENDIF
    DT

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    Code:
    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

    Code:
    
    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
    Last edited by Acetronics2; - 25th June 2009 at 13:30.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  3. Write Onewire data toa I2C memory / read ASCI
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 16th November 2008, 19:19
  4. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 15:04
  5. Interrupt/timer not really interrupting...
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd May 2005, 22:05

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts