Page 1 of 1

SUBs

Posted: Wed Dec 09, 2009 2:21 pm
by izidor
I have a little problem with SUBs. I'm not sure if anyone can help me with this without looking at the code, but here I go.
In my program I have more than 10 SUBs (that changes nothing) and I call one from another. And here goes the problem: very often after a few secondes previous SUB loads without me doing anything.
Has anyone had a problem like this? If yes, PLEASE HELP ME

Posted: Wed Dec 09, 2009 3:17 pm
by Anonymous
When you run a sub from the main code it will go through and run the subs code and return to where it was. The same is true when you run a sub from a sub, the sub that you called from the sub will run then return to the original sub. The example demonstrates this best.

Code: Select all

DECLARE SUB Test1 ()
DECLARE SUB Test2 ()

CALL Test1

SUB Test1
PRINT "1"
CALL Test2
PRINT "3"
END SUB

SUB Test2
PRINT "2"
END SUB

Output will be

1
2
3

Posted: Wed Dec 09, 2009 4:11 pm
by burger2227
Beware of recursive calls! IE calls that go back and forth between two SUBs. Error will be "Out of Stack Space".

You should have some kind of condition for calling a SUB or it will run every loop until you leave the loop.

Same with FUNCTIONs.

Ted

Posted: Wed Dec 09, 2009 4:36 pm
by izidor
Yes that is it, now i just need to figure out how to solve it.
Thanks mates!