QB Knowledge Base > Technical Articles > Number 3

A Modular Programming Way in QB

In previous articles, we discussed the use of modules in structured programming, but we didn’t go into details of using them in QB programming. In this article, we will talk about using different kinds of modules to organize large projects properly.

Two Kinds of Modules
In QB, we have modules and include files. Based on their usage, we call the first group "Code Modules" and the other "Include Modules".

Include Modules
In QB traditions, these files usually have .BI extension. Include modules are mainly used for containing declarations of procedures and functions, variables, global variables (declared using COMMON statement), user-defined types and so forth. Include modules are quite useful for sharing declarations. Here’s a list of some of their most important uses:

There is one important point about include modules; Do not put executive commands in an include module. Doing so may cause errors if you put some non-executive commands (such as DECLARE, COMMON, etc.) after include statement.

Code Modules
Code modules are the means of splitting code discussed in the article "Coding Techniques". The main ideas of using these modules can be found in that article. These files -that in QB traditions have .BAS extension- form the main body of your project.

How to do it all?
We talked a lot about modules. But how can these techniques be used in QB? Here I’ll show you the way QB manages multiple modules. (Remember that early versions of QB do not support modules).

Each QB project contains a main module which has the starting point of the program. This startup code is the module-level code of the main module. Other modules should not have module-level code (In fact, they can; But the code will never be executed). Procedures in other modules are called from the main module (or from a procedure the main module calls).

To create a multi-module project from within QB environment, open your module (or create it), then from the File menu choose "Load File" or "Create File", enter (or choose) the module you want to add to the project, and select OK. The module will be added to the project. You can switch between modules by choosing Subs from View menu or by pressing F2. When you add a module to the project, QB creates (if necessary) a project file with the same name as the main module and .MAK extension, and adds the name of the modules to it. Then each time you open the main module, QB finds and opens the other modules (The project file should be in the same folder as the main module).

Conclusion
It is a great method to organize your project in modules. If you have not tried this method so far, try it in your next project and see the results.

By: Homayoon.P.A.
December 5, 2002


Originally posted on Sepent Technologies.