SELECT CASE for ranges of values


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    caverman's Avatar
    caverman Guest


    Did you find this post helpful? Yes | No

    Unhappy opps, need to add more

    or something like
    select case PulseLength
    case is > 165 and is < 176
    OutValue=0
    case is > 184 and is < 192
    OutValue=1
    end select

    Dirk

  2. #2
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    Seems like maybe some 'IF... THEN's might work out better?

  3. #3
    caverman's Avatar
    caverman Guest


    Did you find this post helpful? Yes | No

    Smile Thanks

    Funny how late at night one gets stuck into a Select method without thinking of the obvious easy If solution

  4. #4
    caverman's Avatar
    caverman Guest


    Did you find this post helpful? Yes | No

    Lightbulb But

    But maybe the PICBASIC people could add the CASE x TO y variety that some BASICs have.

  5. #5
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    caverman, Why make a mountain out of a Mole hill. Just do this:

    select case PulseLength
    case is < 165
    you don't want these values because they are below 165 so do something
    case is < 176
    OutValue=0
    case is < 184
    you don't want these values because they are between 176 and 184 so do something
    case is < 192
    OutValue=1
    case else
    you don't want these values because they are between 192 and 255 so do something
    end select

    This is the correct way as far as I can see to do this type of compare situation. If you were to use "IF" statements and try to capture all posibilities the code would look much different.

    Dave Purola,
    N8NTA

  6. #6
    Join Date
    May 2004
    Location
    New England
    Posts
    164


    Did you find this post helpful? Yes | No

    Default

    That looks like a nice clean solution Dave!

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


    Did you find this post helpful? Yes | No

    Cool

    Why not using the statement below?



    IF PulseLength > 165 AND PulseLength < 176 THEN
    OutValue=0
    ELSE
    IF PulseLength > 184 OR PulseLength < 192 THEN OutValue=1
    ENDIF


    ----------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

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

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