Variable Declaration
You declare a variable to specify its name and qualities.
You use the statement Dim
.
Its location and contents give a variable its qualities.
For information on how to make correct names, see Declared Element Names.
Declaration scopes
Local and member variables
A local variable is a variable declared in a procedure. A member variable is a member of a declared type. You declare it in module scope. It can be a member of a class or structure, but not in a procedure internal to that class or structure.
Shared and instance variables
TODO
Declaring data type
The clause As
in the declaration statement lets you give the data type or object type of the declared variable.
The permitted types follow:
- An elementary data type (
Int32
,Real64
, andString
are examples) - A composite data type (arrays and structures are examples)
- An object type or class
- A trait
You use the clause In
in the declaration statement to declare floating-point variables with a related unit of measure.
The expression after In
is usually a unit declared with the statement Unit
.
But it can also be a basic unit declared with Base Unit
.
You can declare many variables in one statement with the same data type. But it is not necessary to write the data type more than one time. Some examples follow:
' Declare three integer variables.
Dim i, j, k As Int32
' Declare one mass-unit variable and two floating-point variables.
Dim w In kilograms, x, y As Real64
Qualities of declared variables
TODO