Back to index
|
Dim statement
Used to declare and allocate storage space for variables and arrays.
|
Format:
Dim name[ (boundlist) ] [ As type ]
Syntax:
- name
Required. Name of the variable. Must be a valid SBasic identifier.
You can declare as many variables as you like in the same declaration
statement, specifying the name part for each one and supplying
the boundlist part for arrays. Multiple variables are separated by commas.
You can declare several variables to be of the same data type.
You can also specify different types for different variables or
groups of variables. Each variable takes the data type specified in
the first As clause encountered after its name part.
- boundlist
Optional. List of non-negative integers representing the upper bounds
of the dimensions of an array variable. Multiple upper bounds are
separated by commas. An array can have up to 3 dimensions.
Each value in boundlist specifies the upper bound of a dimension, not
the length. The lower bound is always zero, so the subscript for each
dimension can vary from zero through the upper-bound value (including
upper-bound value!).
- type
Optional. Data type of the variable. Can be Integer, Floating or String;
or the name of structure. You can use a separate As clause for each
variable being defined, or you can define several variables to be
of the same type by using a common As clause.
If you do not specify type, the variable can always change its type.
If you do specify type, the data assigned to variable
always converted to its type.
Remarks:
Variables declared with Dim are available to all code within the region
containing the Dim statement. If they are declared in a module but outside any procedure or function, they
can be accessed from anywhere within that module.
Variables declared inside a procedure or a function are accessible only
from within that procedure or function.
See also:
- Assign statement: Assigns variable, constant, or expression to variable or array item
- Using arrays
Example:
' Declare variable s. It can change its type freely
Dim s
Dim Number As Integer
Dim MyInt1, MyInt2 As Integer
Dim MyInt As Integer, MyFloat As Floating
' Array declarations
Dim MyArray(50) ' Array of 50 elements
' Matrix is a two-dimensional array of type Integer.
Dim Matrix(3, 4) As Integer
' Matrix3 is a three-dimensional array of type Floating.
Dim Matrix3(5, 9, 5) As Floating
Copyright (c) 2000-2005 by SymbianWare OHG. All rights reserved.
SymbianWare and SymbianWare logo are trademarks of SymbianWare OHG.