Shop OBEX P1 Docs P2 Docs Learn Events
question about PBASIC 2.5 comparative operators' syntax (<, >=, etc) — Parallax Forums

question about PBASIC 2.5 comparative operators' syntax (<, >=, etc)

edited 2005-10-16 23:13 in BASIC Stamp
does anyone know the proper syntax for PBASIC 2.5 for a 'greater than or equal to' statement?· does it matter if there is a space between the > and the =?· does it matter what order the two operators come in?· for example, in my code i have an IF statement with the condition: 'IF variable >= 50'.· i have a feeling that the code is dropping out of this IF statement when the variable gets to 50, not 51 as one would think would happen.· do i need a space between the > and the = or am i totally offbase in my assumption that this is where my error is?·thanks in advance for any help you can offer.·

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-10-16 20:34
    The proper syntax is:

    if a>=b then........

    or, for less than or equal to:

    if a<=b then........

    All this can be found in the Help file.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester yet?
    http://hometown.aol.com/newzed/index.html

    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-16 21:19
    Brad,

    Perhpas you should post your program instead of a fragment -- that will probably shed some light on the problem you're facing.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • edited 2005-10-16 21:33
    this is the subroutine i am running to calculate which pins and chips to activate in a series of external data latches to light a corresponding neon tube.· there are 100 neon tubes in 4 columns.· each column has 4 8-bit latches, where the 25th neon tube in each column is the only one on the 4th latch.· these bottom tubes are not lighting when connected to the stamp, and i feel that it may have something to do with the IF statements dropping out when neon = 25, 50, or 75.·

    CBP_Num_Calculator: 'find the chip, board and pin # from the neon #
    ··· IF Neon = 100 THEN
    ······ TempNum = 0
    ······ ELSE
    ······ IF Neon >= 75 THEN
    ······ TempNum = Neon - 75
    ·········· ELSE
    ·········· IF Neon >= 50 THEN
    ·········· TempNum = Neon - 50
    ·············· ELSE
    ·············· IF Neon >= 25 THEN
    ·············· TempNum = Neon - 25
    ·················· ELSE
    ·················· TempNum = Neon
    ·············· ENDIF
    ··········· ENDIF
    ······· ENDIF
    ··· ENDIF·· ' End of this Loop
    '
    'This following Loop is again conditioning
    ' the variable TempNum to extract the corresponding Pin#
    '
    ··· IF TempNum = 0 THEN
    ······ TempNum = TempNum
    ··· ELSE
    ····· IF TempNum < = 8 THEN·· 'TempNum minus the number of pins on a chip (8)
    ········ TempNum = TempNum -1
    ········ ELSE
    ········ IF TempNum > 16 THEN
    ··········· TempNum = TempNum - 17· 'TempNum minus twice the number of pins
    ··········· ELSE
    ··········· TempNum = TempNum - 9· 'Just the 8 pins on their own
    ········ ENDIF
    ····· ENDIF··· ' End of this loop
    · ENDIF
    '
    ·· PinNum = TempNum········· ' Final Pin#
    ·· BoardNum = ( Neon - 1 )/25· ' Find Board# subroutine
    '
    ' Find Chip# Subroutine
    '
    ··· ChipNum = (Neon-1)/8
    ··· ChipNum = ChipNum + BoardNum
    RETURN····· ' END of CBP#Calculator

    i have also been unable to find any documentation of the syntax for the logical (<, >, >=, etc.) operators anywhere in the help guide or the stamp 2p manual.·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-16 22:22
    SELECT-CASE is a *better* choice than stacked IF-THEN (I never go more than one nested IF-THEN).· Like this:

    · SELECT neon
    ··· CASE·100
    ····· tempNum = 0
    ··· CASE·75 TO 99
    ····· tempNum = neon - 75
    ····CASE·50 TO 74
    ····· tempNum = neon - 50
    ····CASE·25 TO 49
    ····· tempNum = neon - 25
    ··· CASE·ELSE
    ····· tempNum = neon
    · ENDSELECT

    There are other methods in PBASIC (you could do some trikery with LOOKDOWN), but this solution, I think, is the most straightforward.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-16 22:25
    Hmmm... after looking at my own post·it·occured to me you could do it with one line of code:

    · tempNum = neon // 25

    That's better, isn't it?· I love the modulus operator!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • edited 2005-10-16 23:13
    thanks, i'll try both of those and let you know how things go.
Sign In or Register to comment.