Broken Case statement Logic


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Default

    ... actually if I have PBP show me the 'DIG1' of the value that was 27, it is actually 27.7... it needs to be just 27.. How does one round using PBP?

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


    Did you find this post helpful? Yes | No

    Default

    Tom, Where is the value for the variable TC1 comming from?

    Dave Purola,
    N8NTA

  3. #3
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Default

    It is coming from an array of 2 HEX bytes, which are then converted to binary. In the case I am using, the

    the value '44308' is what TRACID_ID is in this example..

    SSD4= (ssmax[1]>>4)
    SSD3= (ssmax[1] & $f)
    SSD2= (ssmax[0]>>4)
    SSD1= (ssmax[0] & $f)

    TracID_D=(ssd4*4096)+(ssd3*256)+(ssd2*16)+ssd1' convert to dec

    TC1=(TracID_D/1600)

    I have attached a spreadsheet that does this also. It uses an "INT" function to keep the result of the TracID_D/1600 rounded to 27. In PBP I need an equivalent function. Otherwise the answer is 27.7 and that messes up the CASE statement.

    IN the excel example, if you remove the INT function, it gives 27.7 also.

    TG
    Attached Files Attached Files

  4. #4
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Default

    WOW!! I just tried setting my value to 27 manually, and it STILL does not work!!

    Check this out:


    TC1=27


    Select Case TC1
    case 0
    TracID1 = " "
    case TC1 < 27 'A-Z
    TracID1 = TC1 + 64
    case TC1 >= 27 '0-9
    TracID1 = TC1 + 21
    case 37
    TracID1 = ":"
    case 38
    TracID1 = "."
    case else
    TracID1 = "$"
    End Select

    The result is "[", when it should be "0"!!! How could I be setting a value of "27" and having this kind of result?

    TG

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


    Did you find this post helpful? Yes | No

    Default

    Tom, If you would please try the code exactly as I have written it in my first reply and tell me what the results are.

    Dave Purola,
    N8NTA

  6. #6
    Join Date
    Feb 2005
    Location
    Bellevue
    Posts
    125


    Did you find this post helpful? Yes | No

    Wink

    The answer was to not use the CASE statement at all.. It looked like it was failing somehow internally. So I moved to:

    If TCX = 0 then TracID1 = " "
    If TCX < 27 then TracID1 = TCX+64
    If TCX >=27 then TracID1 = TCX+21
    If TCX = 37 then TracID1 = ":"
    If TCX = 38 then TracID1 = "."
    if TCX > 38 then TracID1 = "$"

    I think the code is smaller, and best of all it works.

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


    Did you find this post helpful? Yes | No

    Default

    Tom, It only goes to show, There's more than 1 way to skin a cat.......

    Dave Purola,
    N8NTA

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 05:47
  2. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 09: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, 20:19
  4. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 16:04
  5. Interrupt/timer not really interrupting...
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd May 2005, 23: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