Shop OBEX P1 Docs P2 Docs Learn Events
Error Message on PBASIC 2.5 — Parallax Forums

Error Message on PBASIC 2.5

James AndersonJames Anderson Posts: 52
edited 2006-07-17 17:29 in BASIC Stamp
on a program i wrote in PBASIC 2.5 , i get an error message saying "ELSEIF must be preceded by IF" when I clearly typed IF.
could someone please explain this to Me?
thanks,

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
There once was a lady named Bright
who traveled much faster than light
She departed one day in a relative way
and Returned on the Previous Night

Cheers,
Wannabe Ub3r Geek

World of Warcraft
Star Trek official website
Google (Man's best friend...)

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2006-07-17 00:47
    The problem is the ELSE THEN. Leave out the THEN.
  • James AndersonJames Anderson Posts: 52
    edited 2006-07-17 01:34
    Tried that, but it still doesnt work.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There once was a lady named Bright
    who traveled much faster than light
    She departed one day in a relative way
    and Returned on the Previous Night

    Cheers,
    Wannabe Ub3r Geek

    World of Warcraft
    Star Trek official website
    Google (Man's best friend...)

    Post Edited (wannabe uber-geek) : 7/17/2006 1:38:23 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2006-07-17 01:55
    Wannabe -

    This seems to work okay:

    IF pulse5 < 1500 THEN
    SEROUT lcd , lcdbaud , [noparse][[/noparse]18] 'check ch5 turn off backlight if switch off
    ELSEIF pulse5 > 1500 THEN
    SEROUT lcd , lcdbaud ,[noparse][[/noparse]17] 'vice versa
    ELSE
    SEROUT lcd , lcdbaud , [noparse][[/noparse]"error!"]
    ENDIF

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
  • LarryLarry Posts: 212
    edited 2006-07-17 03:33
    here's what I think is happening--

    Pbasic originally had

    IF (condition) THEN (Statements or Label)
    all on the same line, and you can still write code that way. (it's the only way on a Stamp1)
    The interpreter Knows the IF statement is done at the end of the line.

    But, when you use the expanded ELSEIF, ELSE, ENDIF construct, you need to put the-- (Statements or Label) -- part on the following line to tell the interpreter you are following the new construct.

    You code needs to look like this:


    IF (condition) THEN
    (Statements or Label)

    ELSEIF (condition) THEN
    (Statements or Label)

    ELSE
    (Statements or Label)

    Endif


    If THEN is the last thing on the line, the interpreter knows the IF construct isn't over yet.
    You are getting the error because the interpreter thinks you wrote code the old way and the original IF statement is finished.

    It is looking for the IF statement for the new method in the code that follows.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-07-17 14:11
    Larry is correct...Your code did have another error regarding the ELSE...THEN...Shown below is the correct formatting of the code...I hope this helps.
      IF pulse5 < 1500 THEN
        SEROUT lcd , lcdbaud , [noparse][[/noparse]18] 'check ch5 turn off backlight if switch off
      ELSEIF pulse5 > 1500 THEN
        SEROUT lcd , lcdbaud ,[noparse][[/noparse]17]   'vice versa
      ELSE
        SEROUT lcd , lcdbaud , [noparse][[/noparse]"error!"]
      ENDIF
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • James AndersonJames Anderson Posts: 52
    edited 2006-07-17 17:29
    OK it works now...Thanl<s for all the tips.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There once was a lady named Bright
    who traveled much faster than light
    She departed one day in a relative way
    and Returned on the Previous Night

    Cheers,
    Wannabe Ub3r Geek

    World of Warcraft
    Star Trek official website
    Google (Man's best friend...)
Sign In or Register to comment.