Purpose
Defines one or more global variables.
Syntax
Global var_name [ , var_name... ] As var_type
[ , var_name... ] As var_type... ]
var_name is the name of a global variable to define.
var_type is integer, float, date, logical, string, or a custom variable Type.
Description
A Global statement defines one or more global variables. Global statements may only appear outside of a sub procedure.
The syntax of the Global statement is identical to the syntax of the Dim statement; the difference is that variables defined through a Global statement are global in scope, while variables defined through a Dim statement are local. A local variable may only be examined or modified by the sub procedure which defined it, whereas any sub procedure in a program may examine or modify any global variable. A sub procedure may define local variables with names which coincide with the names of global variables. In such a case, the sub procedure's own local variables take precedence (for example, within the sub procedure, any references to the variable name will utilize the local variable, not the global variable by the same name). Global array variables may be re-sized with the ReDim statement. Windows, global variables are "visible" to other Windows applications through DDE conversations.
Example
Declare Sub testing()
Declare Sub Main()
Global gi_var As Integer
Sub Main()
Call testing
Note Str$(gi_var) ' this displays "23"
End Sub
Sub testing()
gi_var = 23
End Sub
See Also:
Dim statement, ReDim statement, Type statement, UBound() function