[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
VB2Delphi » WTL » Star7 » J2SE » IEvents » structure » talk:TurboCpp » address » Prolog » PnP » QbasicFAQ_Gosub
What's the difference between a SUB module and a GOSUB?


Back to QBasic FAQ Main Page.

QBasic allows the programmer to create SUB modules that are accessed separately from the main module, where GOSUBS are program directions that are invoked at any level.

Similar to a GOTO, GOSUB routes the program instructions to a new line to execute that code. The last line will need to be RETURN, so that program execution returns to the line of below where it left out. QB allows for a RETURN <Line Identifier>, but that also allows for poor programming practice. You should just RETURN where you left from to avoid unexpected results.

SUBs are separate modules that are created with the DECLARE SUB statement. Module level SUBs are great for redundant and recursive operations, and they accept parameters. The parameters are passed at the time of CALL, and usually are what the SUB uses to complete it's work.

Declared SUB routines are unaware of variables in other modules unless they are passed as parameters, or defined as SHARED. (Hint: You can use COMMON SHARED, but it uses more resources than if you DIMension them shared.)

A secondary benefit to creating SUB modules is that the amount of memory used for program loading is not as affected by the module size. Main Module level is restricted to 64K, but module code can be included making it much larger.

last edited (December 9, 2002) by KDivad Leahcim, Number of views: 3383, Current Rev: 2 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Site Management by Lars Hagelin at Kontantkort.se.