SELECT CASE for ranges of values


Closed Thread
Results 1 to 18 of 18

Hybrid View

  1. #1
    caverman's Avatar
    caverman Guest

    Question SELECT CASE for ranges of values

    Sure this may be basic stuff (pun intended) but can you have a range of values for a select case

    Eg Visual basic allows
    SELECT CASE PulseLength
    CASE 165 TO 176
    blah
    CASE blah...

    I want to do something like
    select case PulseLength
    case 165 to 176
    OutValue=0
    case 184 to 192
    OutValue=1
    end select

    But it don't work

    Any ideas?
    Thanks
    Dirk

  2. #2
    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

  3. #3
    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?

  4. #4
    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

  5. #5
    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.

  6. #6
    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

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