ModularizeIt
How to split a part of your program into a module

If you try to compile a program with more than 64K of code the compiler will isue an error.
To solve this problem you must split your code in several modules(provided you are using SUBs and FUNCTIONS...).
For more advanced solutions, read PushingTheLimitsOfQB in this FAQ

A quick way to get a working separate module is:

-Remove some (related) subs and functions and put them in a second .bas file.
-Copy all the DECLARE lines from your main program to the top of the second file. You dont' really need them all but it will work.

-Convert all your DIM SHARED declarations to COMMON SHARED and copy them to the top of the second file.
-Add to your main module, after the COMMON SHAREDs DIM's (without SHARED) for all arrays you were dimensioning with DIM SHARED, as COMMON SHARED it's just a declaration and won't dimension anything.

-In case you were using SHARED in the subs and Functions instead of DIM SHARED in the main module you must create COMMON (not SHARED) declarations for all SHARED variables and put the m at the top of both modules. In this case you don't need to create a new DIM for arrays.

-Copy /move your TYPE declarations to the second file if there are variables of this type in the second file.

-Also copy all CONST definitions in the main part of your program to the top of the second file.

-Move each DATA line to the main part of the module if it will be READ from a SUB/function in the module.

This part must be done only once
-Enable Full Menus if you have them disabled
-Load both files in the IDE, one with Open Program and the other one with Load File.
-Then go to Run>Set Main Module and select your main program.
Next time you load your program QB will load all modules needed automatically


If i'm not forgetting nothing it should run and compile correctly....

NOTE1: If you gather all the duplicated DECLARE SUB, DECLARE FUNCTION, COMMON SHARED, COMMON, CONST and TYPE declarations in a separate file xxx.BI you can add '$INCLUDE 'xxx.bi' at the top of both modules and avoid having to maintain two sets of declarations.

NOTE2: Executable code at module level in modules different from main one will never execute.

NOTE3: Calling a function in another module is slow. If speed is an issue, try to get the critical part of the program in a single module


ModularizeIt - page last edited 2003-07-26 02:51:46 by 62.14.163.76 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster