Shop OBEX P1 Docs P2 Docs Learn Events
methods with arguments in Pbasic? — Parallax Forums

methods with arguments in Pbasic?

christiandchristiand Posts: 7
edited 2009-10-20 18:36 in BASIC Stamp
Hi! I am looking for a command in Pbasic similar to methods in Java, where I can send in an argument.
I found GOSUB, but it doesn't seem I can send in an argument to it. This is what I want to do.

' {$STAMP BS2}
' {$PBASIC 2.5}

sData   VAR     Byte
DO
SERIN 16, 16468, [noparse][[/noparse]DEC sData]

GO_SUB method(sData) 'send variable sData to other instance of program

method(sData):
move motor to position sData 'pseudo-code

LOOP

This is how it would look in java:

moveMotor(100);

moveMotor (int pos) {
motorPosition = pos;
}

Is there anything similar in Pbasic?

regards / Christian

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-10-20 18:31
    PBasic doesn't have any subroutine calls other than GOSUB and that doesn't provide for arguments or a return value. You'll have to do that by leaving the arguments you want in global variables of your choosing and returning any result the same way.
  • allanlane5allanlane5 Posts: 3,815
    edited 2009-10-20 18:36
    Well, something similar can be done:

    T1 VAR BYTE
    sData VAR Byte

    DO
    · SERIN 16, 16468, [noparse][[/noparse]DEC sData]
    · T1 = sData
    · GOSUB MoveMotor ' (t1)· ' The 'tick' being a comment.
    LOOP

    sub MoveMotor
    · MotorPosition = T1
    · return
Sign In or Register to comment.