Global Command

Purpose

Used to declare global variables and allocate storage space.

Syntax

Global [Dim] varname[()] [As [New] type] [ = value], …

Global type varname1 [ = value], varname2 [ = value], …

Global varname1$ [ = value], varname2% [ = value], …

varname: name of variable

type: Optional. Data type of the variable; may be Byte, Boolean, Card, Short, Word, Integer, Long, Large, Currency, Single, Double, Date, String, (for variable-length strings), String * length (for fixed-length strings), Object, Variant, a user-defined type, or an object type. Use a separate As type clause for each variable being defined.

Description

The New keyword enables implicit creation of a few GFA-BASIC 32 objects, like DisAsm, Collection, StdFont, Font, StdPicture, Picture, CommDlg, and ImageList. If you use New when declaring the object variable, a new instance of the object is created on first reference to it, so you don't have to use the Set statement to assign the object reference. The New keyword can't be used to declare variables of any intrinsic data type.

Variables declared using the Global (or Public) statement are available to all procedures in the program.

If you don't specify a data type or object type and there is no Deftype statement in the module, the variable is Variant by default.

Variables can be initialized while they are declared.

When a variable isn't explicitly initialized, a numeric variable is initialized to 0, a variable-length string is initialized to a zero-length string (""), and a fixed-length string is filled with zeros. Variant variables are initialized to Empty. Each element of a user-defined type variable is initialized as if it were a separate variable.

Example

Global a As Int, b%, d As Handle, e$

Global Double a, b, c, d, e

Dim a As Int, b%

Global Dim a(100) As String

Global a(100) As String

Dim a$(100)

Global dis As New DisAsm

Dim col As New Collection

Remarks

If you use Dim in the main part of a program, the variables will be declared Global. When Dim is used in a sub the variables are local.

See Also

Dim, Local, Static

Boolean, Byte, Card, Short, Word, Int16, Long, Int, Integer, Int32, Int64, Large, Single, Double, Currency, Date, Handle, String, Variant, Object

{Created by Sjouke Hamstra; Last updated: 08/10/2014 by James Gaite}