Shop OBEX P1 Docs P2 Docs Learn Events
pbasic help — Parallax Forums

pbasic help

Robert25Robert25 Posts: 53
edited 2006-02-14 23:02 in BASIC Stamp
Hi... hope this is the correct forum to post this.

I am having a problem with a pbasic (2.5)·code that keeps giving me an error message during syntax check.· I attached that portion of the code below that is a do loop.· When I run the syntax check, I receive the following error message:· error 141 - expected a constant, variable, unary operator, or "("
Naturally, all the variables and such were defined earlier.

Since I a still a bit new to programming, can someone give me a clue what to look for to solve the issue????

Code:
·DO
··· GOSUB Get_Sonar···························· ' get sensor value
··· inches = rawDist ** RawToIn················ ' convert to inches
··· cm = rawDist ** RawToCm···················· ' convert to centimeters
··· DEBUG CRSRXY, 15, 3,······················· ' update report screen
········· DEC rawDist, CLREOL,
········· CRSRXY, 15, 4,
········· DEC inches, CLREOL,
········· CRSRXY, 15, 5,
········· DEC cm, CLREOL,
········· CRSRXY, 15, 6,
········· DEC cmd, CLREOL
··· PAUSE 50
··· IF inches < 6 THEN GOSUB Play_msg
'··· BRANCH cmd, [noparse][[/noparse]Play_Msg, Play_Msg]
· LOOP
· GOTO Main
· END
·

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-14 21:05
    Robert25 -

    Are you using the following directive at the beginning of your program, if not, you need to add it in:

    ' {PBASIC 2.5}

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • Charlie JohnsonCharlie Johnson Posts: 147
    edited 2006-02-14 21:10
    I tested the code syntax by adding var declarations and the labels for the subroutines... and it compiled without complaint.

    Could the problem be a missing constant, variable, unary operator, or "(" further up in your code?
  • Robert25Robert25 Posts: 53
    edited 2006-02-14 21:18
    Yes, I use the 2.5 declaration at the beginning of the code.
    It is possible that something else is missing, eg constant, variable etc.

    Why would it give me the syntax error from the "do" in the do loop???

    if the "constant, variable etc." is outside the loop???

    If I understand correctly, I should be looking for a missing constant or variable declaration???
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-14 21:29
    Robert,

    ·· There is too much missing and generating all kinds of errors.· Why not post the exact code you are using as an attachedment (Not pasted) so we can compile it and see what is happening?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-02-14 21:34
    Robert25 -

    Chances are better than even that you're not using curley brackets, as you should be.

    This is correct:

    ' {PBASIC 2.5}

    This is INCORRECT:

    ' [noparse][[/noparse]PBASIC 2.5]

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • metron9metron9 Posts: 1,100
    edited 2006-02-14 21:36
    I don't see a problem


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    inches VAR Word
    rawdist VAR Word
    rawtoin VAR Word
    cm  VAR Word
    rawtocm VAR Word
    cmd VAR Word
    
    
    
    main:
    
    Code:
     DO
        GOSUB Get_Sonar                             ' get sensor value
        inches = rawDist ** RawToIn                 ' convert to inches
        cm = rawDist ** RawToCm                     ' convert to centimeters
        DEBUG CRSRXY, 15, 3,                        ' update report screen
              DEC rawDist, CLREOL,
              CRSRXY, 15, 4,
              DEC inches, CLREOL,
              CRSRXY, 15, 5,
              DEC cm, CLREOL,
              CRSRXY, 15, 6,
              DEC cmd, CLREOL
        PAUSE 50
        IF inches < 6 THEN GOSUB Play_msg
    '    BRANCH cmd, [noparse][[/noparse]Play_Msg, Play_Msg]
      LOOP
      GOTO Main
      END
    
      get_sonar:
      RETURN
    
      play_msg:
      RETURN
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Think outside the BOX!
  • Robert25Robert25 Posts: 53
    edited 2006-02-14 22:25
    OK here is the complete code listing as an attachement.· Please keep in mind this is a "draft" code as it is in "development".
    Just for a previous post, I use the buttons in the editor to insert the Pbasic and stamp I am using...· they automatically insert the braces...· {}.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-14 22:46
    Robert,

    ·· The reason this is happening to your DO statement is that the previous line of code has a comma at the end.· This tells the compiler that the next line is part of it.· Remove the comma and you should be okay.· Oh, and the 'j' artifact in your DEBUG section right below it.· Oh, you also have a Check_Busy call and that label doesn't exist.· After that it works.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • Robert25Robert25 Posts: 53
    edited 2006-02-14 23:02
    You're absolutely correct. Made the corrections and it works...

    ah... for the wnat of an extra comma....
Sign In or Register to comment.