Dim Statement
Declares variables and allocates memory for them.
Syntax
[ modifier ] { Dim | Var } declarator [ , declarator ]…
Parts
modifier- One of these:
DimorVar- Mandatory keyword.
DimandVarare usually equivalent. - If you use the directive
@Option Dim,Varbecomes an error. And if you use@Option Var,Dimbecomes an error. See @Option Directive for more information. declarator- Mandatory one or more declarations with a comma between each.
Declarator
name [ ( [ dimensions ] ) ] [ As type | In unit ] [ = initializer ]name- Mandatory name for a variable
dimensions- Optional one or more integer expressions with a comma between each
type- Optional data type
unit- Optional unit of measure
initializer- Optional expression having a data type compatible with
typeorunit.
Instructions
Setting an initial value
TODO
Declaring multiple variables
Arrays
See Arrays for more information.
Default types and values
If you do not give a data type, the compiler selects a data type. If you supply an initializer, the variable's data type comes from the data type of the initializer. See the table that follows for the rules.
| If you specify | The compiler sees it as |
|---|---|
|
|
|
|
|
|
|
|
If you do not supply a data type or initializer, the name of the variable selects the data type.
If you specify
Dim a%, b!, c$, #d
The compiler sees it as
Dim a% As Int32 = 0
Dim b! As Real64 = 0.0
Dim c$ As String = ""
'??? Dim #d As Object = #Null
Shared lifetime
All variables declared at module level have shared lifetime if @Shared is specified or not.
Examples
TODO