Dim
Statement
Declares variables and allocates memory for them.
Syntax
[ @Shared ] { Dim | Var } declarator [ , declarator ]…
Parts
@Shared
- Optional modifier specifies that each variable can have a small scope but keeps its value during an application's full run-time.
Dim
- Mandatory unless you use
Var
. - Mandatory if you use the directive
@Option Dim
. See @Option Directive for more information. Var
- Mandatory unless you use
Dim
- Mandatory if you use the directive
@Option Var
. 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
type
orunit
.
Instructions
Setting an initial value
TODO
Declaring multiple variables
Arrays
See Arrays.
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