Modules

A Module is a named section of code that begins with a Module statement an ends with an End Module statement. Modules may contain variable declarations, procedures, and class definitions. Modules can only appear at the top-level of a file. They cannot appear inside of other modules or classes.

Scope of Items within Modules

Modules provide a simple way to group variables, procedures, and classes, without concern about name conflicts.

Module variables, procedures, and classes can be declared as either Public or Private. By default these items are all Private. A Private item may not be referenced outside of the module in which it is declared. A Public item may be referenced outside of a module by using the syntax: module_name.item_name. As a special case, if item_name is unambiguous within all loaded modules, the module_name. may be omitted.

All variables declared within a module (and not within a class or procedure) are implicitly Shared, so they can be referenced within any procedure contained in the module. Consequently, only one copy of each implicitly Shared variable value can exist. All references to the variable access the same value. If a variable has any initializer clauses, the initialization occurs once when the main thread for the Module is started. Const symbols behave the same as variables, except their values cannot be changed once they are initialized.

Special Initialization Procedures

If a user Sub procedure named Init is defined within a module, it is executed as part of the module initialization, before the startup procedure begins.

An internal Sub procedure named _Init is automatically generated to perform module-level initialization. Do not attempt to create a procedure with this name.