Is it possible to CALL the main module in a program?

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
Aikaterine
Newbie
Posts: 1
Joined: Wed Jun 20, 2007 6:15 pm
Contact:

Is it possible to CALL the main module in a program?

Post by Aikaterine » Wed Jun 20, 2007 6:18 pm

If I'm programming a subroutine, can I make it go back to the main thing? If I can, what is the syntax? Thanks ^_^
-Aika

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: Is it possible to CALL the main module in a program?

Post by moneo » Wed Jun 20, 2007 7:03 pm

Aikaterine wrote:If I'm programming a subroutine, can I make it go back to the main thing? If I can, what is the syntax? Thanks ^$$$^
-Aika
First of all, are you referring to a SUB or a gosub type subroutine?

In the case of a SUB:
- The SUB usually gets called by the main module, although SUBs can also be called by other SUBs or Functions.
- You get back to the main module or whoever called the SUB by it's ending statement of END SUB.

In the case of a gosub subroutine:
- Subroutines are invoked via a GOSUB. They can be invoked from the main module or from a SUB or Function when the subroutine is part of these.
- You get back from a subroutine by it's ending statement of RETURN. You can have multiple RETURNs in a subroutine, although it's not good practice.
- Beware of exiting a subroutine using a GOTO. This may eventually cause a stack overflow error.

Regards..... Moneo

OPRESION
Veteran
Posts: 61
Joined: Tue Jan 16, 2007 4:15 am
Location: Mexico

Post by OPRESION » Thu Jun 21, 2007 7:00 am

Use Exit Sub anywhere into the subrutine

Erik
Coder
Posts: 29
Joined: Wed Jun 20, 2007 12:31 pm
Location: LI, NY
Contact:

Post by Erik » Mon Jun 25, 2007 10:24 am

Once your sub ends it dumps you right back to the line after it was called. :)

Post Reply