SUBs

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

SUBs

Post 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
Anonymous

Post 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
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post 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
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Post by izidor »

Yes that is it, now i just need to figure out how to solve it.
Thanks mates!
Post Reply