Private and Public Definitions

By default, all subroutines, functions, and user-defined types (including enumeration definitions) may be accessed from other modules. To prevent other modules from accessing procedures or user-defined types precede the definition with the Private keyword:

Private Sub MyBeep

   Beep : Beep

End Sub

 

In contrast to procedures, the global variables defined at the top of one module are not available to other modules unless they are declared using a Public statement. When used for variable declarations, the Public statement has the same syntax as the Dim statement:

Public universal_data As String

 

The names of all definitions, even private ones, are visible in other modules. To avoid errors due to name conflicts you must avoid using the same procedure, type, and variable names in more than one module. A common technique for avoiding name conflicts is to append a prefix to the names of global variables and procedures. For example, if you write a module of text-processing functions, you might prefix each function name with txt, e.g., txtFunction1.

 

 

See Also

Module Types

The '#Uses Line

Module Properties

Defining Object Properties and Methods

Class Module Example

Scripter BASIC Language