Variables

<< Click to Display Table of Contents >>

Variables

Declaring variables

Variables are created with the statements Dim or Static. By default, variables have the type Variant. If a different data type is desired, you must specify it in the declaration with As Type or with a type suffix (e.g. % for Integer) (see the section Data Types).

' Declare X as a variant variable:

Dim X

' Declare X as an integer variable:

Dim X As Integer

' Same as the statement above:

Dim X%

' Multiple declarations in a line:

Dim X%, Name$

Scope of variables

Variables can be either local or global:

Global variables are created with a Dim statement outside of a procedure. They can be accessed anywhere.

Local variables are created with a Dim or Static statement within a procedure (subroutine or function). They are only available within the procedure.