PDA

View Full Version : methods with arguments in Pbasic?



christiand
10-21-2009, 12:28 AM
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, [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

Mike Green
10-21-2009, 01:31 AM
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.

allanlane5
10-21-2009, 01:36 AM
Well, something similar can be done:

T1 VAR BYTE
sData VAR Byte

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

sub MoveMotor
MotorPosition = T1
return