[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
QbasicFAQ_Modular
What is modular programming?


Back to QBasic FAQ Main Page.

Modular programming involves building a program in such a way as to create it in specific sections; modules. This can be done using SUB declarations, GOSUBS, and FUNCTIONS. Using modular structure is preferred because, elements that need to be repeated can be created once, than invoked repeatedly. Good programming practice will also allow you to "transport" SUB modules for inclusion in other programs you create.

A good example:

DECLARE SUB Center(RowPosition, Text$)
'
Center 12, "This text is centered."
Center 13, "So is this text example."
END
'------------------------------------
SUB Center (RowPosition,Text$)
Column = 40 - INT(LEN(Text$)/2)
LOCATE RowPosition, Column
PRINT Text$;
END SUB


The above example allows the programmer to call the SUB Center() any time he wishes to print centered text to the screen.

Now in the QB environment, the SUB would not be shown in the main edit window until it was chosen from the menu. Keeping the SUBs separated like this makes it easier to concentrate on the task at hand, and moves the coding to it's own separate "page" so to speak.

last edited (December 9, 2002) by KDivad Leahcim, Number of views: 1708, 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. Development by Tore Nestenius at .NET Consultant - Synchron Data.