Shop OBEX P1 Docs P2 Docs Learn Events
Help.. Passing a Debug value to a GOTO command? — Parallax Forums

Help.. Passing a Debug value to a GOTO command?

robo101.comrobo101.com Posts: 2
edited 2005-05-06 12:24 in BASIC Stamp
Help...
I would like to enter a value in to the debug window and have my BS2 use the value to determine what code to run by way of the GOTO command..
In short I want the GOTO command to use a variable/value·that I enter from the debug window..

Here is code I think should work but is not..

'################ Start example code ##############
' {$STAMP BS2}
' {$PBASIC 2.5}
myNum VAR Word
GOTO R1
R1:
DEBUG CLS, "Enter a any number: " ' prompt user
DEBUGIN mynum
GOTO mynum
··
R2:
DEBUG "You slected run the gode in " mynum, CR
PAUSE 1000
GOTO R1
R3:
DEBUG "This time you selected " mynum, CR
PAUSE 5000
GOTO R1
'################ End example code ##############

Error: I get an "expected label" in the GOTO of R1:··
(how should I be trying to pass the enterd value such as "R2" to the GOTO??)

Thanks for the help!smile.gif
Shane

Comments

  • kelvin jameskelvin james Posts: 531
    edited 2005-05-06 05:47
    Since you are new to programming in pbasic, i can give a little advice. If you purchased a product with 100 parts to be assembled, and didn't have any directions to put it together, how much sucsess do you think you will have? You might get lucky, but chances are you will give up due to pure frustration. It is a natural tendency to dive in to get something working, but you have to know how it works first. Do yourself a big favour, and read the help section thoroughly. Understand what each command will do, and what it is used for, and how to get a program flow. The reason you are getting the " expected a label " error, is because the GOTO command is used to jump to a program subroutine, which is looking for a " label" , the name of the subroutine code to GO TO. Just have some patience, and have a great learning experience.


    kelvin

    Post Edited (kelvin james) : 5/6/2005 5:53:15 AM GMT
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2005-05-06 06:28
    Shane -

    Parallax PBASIC (as you will learn) has no computer GOTO command per se, but it does have another equivalent command. Take a look in the Help File or better yet in the MANUAL (free for the download) at the ON [noparse][[/noparse]variable name] GOTO [noparse][[/noparse]label 1, label 2 ...] construct.

    Regards,

    Bruce Bates
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-05-06 12:24
    PBASIC 2.5 does have ON-GOTO, so if you can enter a target as a 0-based offset, then you can do what you want.

    · ON offset GOTO Targe0, Target1, Target2
    · ' if here, offset was > 2



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
Sign In or Register to comment.