If Then Range


Closed Thread
Results 1 to 12 of 12

Thread: If Then Range

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You can test various comparison equations with something like this. Just
    compile each one separately.
    Code:
    X CON 10
    
    Main:
        IF (X=5) or (X<=8) THEN   ' 30 words
        @ nop 
        ENDIF
    Code:
    X CON 10
    
    Main:
        IF X => 5 THEN
           IF X < 9 THEN  ' 11 words
             @ nop
           ENDIF
        ENDIF
    Then you could do something like this to save yet a few more words.
    Code:
    X CON 10
    
    ' Upper boundary # = 8
    ' Lower boundary # = 5
    ' Range = 4  (5,6,7,8)
    
    ' IF unknown value (X - lower range #) < range, it's in range.
    
    Main:
        IF (X-5) < 4 THEN  ' 8 words
        @ nop
        ENDIF
    Just place some heavy-duty comments in there so you don't forget what the
    heck it's doing down-the-road...;o]
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    Hey Bruce,

    Wow I had to look at that last example a couple times before it sunk in! But sure enough it does the trick with the least amount of code required. Bravo!

  3. #3
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Bruce you rock. Between Bruce and Melanie they are PICBasic sages.

Similar Threads

  1. Expanding Timer1 counting range
    By sycluap in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 3rd February 2014, 22:00
  2. using a pot to control a time range
    By glkosec in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th June 2008, 19:59
  3. Long range communication
    By Christopher4187 in forum Off Topic
    Replies: 10
    Last Post: - 6th February 2008, 16:12
  4. Sharp GP2D12 Range Finder???
    By Gixxer in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 13th December 2007, 09:21
  5. HPWM frequency range
    By jcsquire in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 16th June 2006, 02:11

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