Shop
OBEX
P1 Docs
P2 Docs
Learn
Events
Help with programming — Parallax Forums
toggle menu
Categories
Discussions
Sign In
·
Register
Sign In
·
Register
Categories
Discussions
Sign In
·
Register
×
Home
›
BASIC Stamp
Help with programming
goofybud16
Posts:
9
2010-01-12 02:12
edited 2010-01-13 13:51
in
BASIC Stamp
Is there such a thing as a Method or function in PBASIC? I am a beginner. I need help. Thanx.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
--
goofybud16
Comments
Duffer
Posts:
374
2010-01-12 02:33
edited 2010-01-12 02:33
GOSUB, but you can't pass parameters. Duffer
vaclav_sal
Posts:
451
2010-01-12 17:19
edited 2010-01-12 17:19
Subroutine will accept parameters.
They are however "common" variables of the program, not specific to subroutine.
Here is an example
'Variable Declaration
·
Test VAR Word
.....
'Variable assigment
Word = 42
.....
'Subroutine
GOSUB Label
'Now Test
·
= 43
.....
' subroutine
Label:
····
Test = Test + 1
return
·
allanlane5
Posts:
3,815
2010-01-13 13:51
edited 2010-01-13 13:51
No, a "subroutine using parameters" would look like:
Gosub MySub, A, B, C
PBasic does not have this -- all variables are global. However, you can implement something like this using
"Temp1" and "Temp1" variables. In which case this looks like:
Temp1=5: Temp2 = 6
GOSUB MySub ' Temp2 = Temp2 + Temp1
MySub:
Temp2 = Temp2 + Temp1
RETURN
Sign In
or
Register
to comment.
Comments
They are however "common" variables of the program, not specific to subroutine.
Here is an example
'Variable Declaration·
Test VAR Word
.....
'Variable assigment
Word = 42
.....
'Subroutine
GOSUB Label
'Now Test·= 43
.....
' subroutine
Label:
···· Test = Test + 1
return
·
Gosub MySub, A, B, C
PBasic does not have this -- all variables are global. However, you can implement something like this using
"Temp1" and "Temp1" variables. In which case this looks like:
Temp1=5: Temp2 = 6
GOSUB MySub ' Temp2 = Temp2 + Temp1
MySub:
Temp2 = Temp2 + Temp1
RETURN