If Then Range


Results 1 to 12 of 12

Thread: If Then Range

Threaded View

  1. #6
    mytekcontrols's Avatar
    mytekcontrols Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Dynamo,

    Here is another way of expressing the same thing.
    Code:
    If x => 5 And x <= 8 Then
    [do something code here]
    Endif
    This does give a simpler look to your basic source code, but unfortunately it will cause PBP to compile it fatter (in otherwords it will take more program space in your PIC chip). Any time you use "And" in your If...Then statements you run this risk. The first code sample I gave you circumvents this problem, but does take a little getting used to.

    Go ahead and try both examples, compiling each, and see the difference in the amount of bytes used.

    edit: I just realized that you can save a heck of a lot more bytes by eliminating the "=>" and "<=" and replacing them with ">" and "<" (see examples below). Of course you will need to adjust your range values to compensate, but I think this would be well worth it for the greatly reduced program space needed.

    Code:
    If x > 4 Then
         If x < 9 Then
         [do something code here]
         Endif
    Endif
    
    ' -or-
    
    If x > 4 And x < 9 Then
    [do something code here]
    Endif
    Hint: Compile all the examples to see the differences in program space required.

    I hope that answers all your questions,
    Last edited by mytekcontrols; - 29th June 2005 at 00:48.

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