Select case...Just wondering....


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2005
    Location
    Up the bush, Western Plains, NSW Au
    Posts
    216

    Default Select case...Just wondering....

    I haven't tried this yet, but my reading of the manual says I should be able to do something like-----

    select case X 'X is the name of a/d variable

    case 0<X<20
    go do something
    case 21<X<40 'or should this be IS >21 AND IS < 40
    go do something different
    case 41<X<60
    go do something different still

    etc, etc.
    Does anyone reckon this will work?

    Just thinking out loud,
    Peter Moritz.

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


    Did you find this post helpful? Yes | No

    Default

    What about these?


    First one works for sure.
    Code:
    SELECT CASE x        
    
         CASE IS < 21   'Between 0 and 20; including 20.
    
         CASE IS > 20 AND IS < 41 'Between 21 and 40 ; including 21 and 40.
    
         CASE IS > 40 AND IS < 61  'Between 41 and 60 ; including 41 and 60.
    
    END SELECT

    For this second one, I expect someone to confirm.

    Code:
    'Once it hits the first matching condition it should not go to the next one.
    'Or will it?
    
    SELECT CASE x        
    
         CASE IS < 21 'Between 0 and 20; including 20.
    
         CASE IS < 41 'Between 21 and 40 ; including 21 and 40.
    
         CASE IS < 61 'Between 41 and 60 ; including 41 and 60.
    
    END SELECT
    Last edited by sayzer; - 29th December 2006 at 16:17. Reason: Added the second example.

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Default

    sayzer,
    go with the second - it works the same as the first
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

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


    Did you find this post helpful? Yes | No

    Default

    Ok, we get (save) more space then, as long as the values are in the same ascending order.

    Muddy, pick the second.


    ---------------------------

  5. #5
    Join Date
    Oct 2005
    Location
    New Jersey
    Posts
    425


    Did you find this post helpful? Yes | No

    Default

    To further the discussion, because I have never used select case before, can you do something like this:

    SELECT CASE x

    CASE IS < 21 led1

    CASE IS < 41 led2

    END SELECT

    I am used to something like this

    If x=1 then
    goto led1
    else
    goto led2
    endif


    Also, an OT question. How do you guys get the code to display in blue?

    Thanks,

    Chris

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Christopher4187 View Post
    To further the discussion, because I have never used select case before, can you do something like this:

    SELECT CASE x
    CASE IS < 21 led1
    CASE IS < 41 led2
    END SELECT

    I am used to something like this

    If x=1 then
    goto led1
    else
    goto led2
    endif

    Chris
    Should work. If it doesn't, reverse the cases around a bit...

    SELECT CASE x
    CASE IS > 20
    GOTO LED1
    CASE IS > 0
    GOTO LED2
    END SELECT

    Sometimes it's all about the order things go in...

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