Public Statement
Declares public variables and allocates storage space.
Note:
Public variables must be declared at script level and not inside any procedure.
Syntax
Public varname[([subscripts])][, varname[([subscripts])]] . . .
Arguments:
-
Varname: Name of the variable; follows standard variable naming conventions.
-
Subscripts: Dimensions of an array variable.
Remarks
Public statement variables are available to all procedures in the same script.
A variable that refers to an object must be assigned an existing object using the Set statement before it can be used. Until it is assigned an object, the declared object variable is initialized as Empty.
You can also use the Public statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements in the array.
The following example illustrates the use of the Public statement:
Example 1:
Public MyNumber ' Public Variant variable.
Public MyArray(9) ' Public array variable.
' Multiple Public declarations of Variant variables.
Public MyNumber, MyVar, YourNumber