![]() |
<< Index >> |
FutureBasic 5 |
dim | statement | |
|
dim as userType declaration1 [,declaration2...]
dim as predefinedType declaration1 [,declaration2...]
dim varName as userType
dim varName as predefinedType
dim
is a non-executable statement that allows the compiler to determine how much storage space should be allocated for the declared variables, arrays and record fields, and identifies their data types. dim
can also be used to affect the relative storage locations of the declared variables, arrays and fields. The basic syntax is the same for dims within a record and outside a record. There are some exceptions such as arrays inside records, see help for begin record.declaration
can have any of the following forms: {varName | [maxLen] stringVar$}
untypedVar as predefinedType
untypedVar as userType
untypedVar as recordType
untypedVar.constant2
varName | [maxLen] stringVar$}(maxSub1[,maxSub2...])
untypedVar (maxSub1 [,maxSub2...]) as predefinedType
untypedVar (maxSub1 [,maxSub2...]) as userType
untypedVar.constant2 (maxSub1 [,maxSub2...])
untypedVar as {pointer to|^|@|.}{predefinedType|recordType}
untypedVar as {Handle to|^^|@@|..}{predefinedType|recordType}
{%|&|&&|&&&|.constant}
maxLen
, maxSub1
, maxSub2
and statExpr
are (non-negative) static integer expressions.
constant
is a (non-negative) literal integer or a symbolic constant; but if a symbolic constant is used, its initial underscore character is omitted.
stringVar$
is a variable name that ends with a "$" type-identifier suffix.
varName
is a variable name that may optionally end with a type-identifier suffix.
untypedVar
is a variable name that does not end with a type-identifier suffix.
userType
is a type name defined in a previous begin record
statement or #define
statement.
recordType
is a type name defined in a previous begin record
statement.
predefinedType
is one of the following: char
, [unsigned] byte
, [unsigned] word
, [unsigned] short
, [unsigned] int
, UInt16
, SInt16
, [unsigned] long
, UInt32
, SInt32
, UInt64
, SInt64
, Rect
, Handle
, RgnHandle
, Str255
, Str63
, Str31
, Str15
, double
, single
.
dim
statement appears within a begin globals
...end globals
block, then the scope of the declared variables and arrays is global. If it appears within the scope of a local
function (but not within a begin globals
...end globals
block), then the scope of the declared variables and arrays is local to that function or procedure block. If dim
appears outside of all local functions and procedure blocks (and outside of any begin globals
...end globals
block), then the scope of the declared variables and arrays is local to "main."dim
statements as you like. The following statement:dim a, b&, c$, d#
dim a, b&
dim c$, d#
dim
statement, which must appear somewhere above the first line where the structure is used. These structures include:xref
or xref@
statement)
byte integers (` , `` ), byte , char , Boolean |
1 byte |
short integers (% , %` ), short , int , SInt16 , UInt16 |
2 bytes |
long integers (& , &` ), long , SInt32 , UInt32 |
4 bytes |
long long integers SInt64, UInt64 |
8 bytes |
Point |
4 bytes |
single precision (! ), single |
4 bytes |
double precision (# ), double |
8 bytes |
Rect |
8 bytes |
Str255 |
256 bytes |
pointer |
4 bytes |
Handle |
4 bytes |
sizeof
function to make a definite determination of the size of the variable.)maxLen
parameter (which cannot exceed 255). If maxLen
is omitted, then the most recent maxLen
specified in the same dim
statement is used. String variables declared using the as Str255
clause always have a maxLen
value of 255.maxLen
has been determined for a given string variable, the actual number of bytes allocated for the variable is:maxLen
+ 1 bytes, if maxLen
is odd;
maxLen
+ 2 bytes, if maxLen
is even;
maxLen
characters to a string variable. The storage space for a record variable equals the sum of the lengths of the record's fields, or the value of constant2
(in bytes).elSize
is the size in bytes of a single array element, then the space allocated for the entire array is given by the following expression:array size = elSize * (maxSub1 + 1) * (maxSub2 + 1) * ...
dim p%(3, 2)
p%()
are stored in this order in memory:p%(0,0)
p%(0,1)
p%(0,2)
p%(1,0)
p%(1,1)
p%(1,2)
p%(2,0)
p%(2,1)
p%(2,2)
p%(3,0)
p%(3,1)
p%(3,2)
dim as int;0, hi as byte, lo as byte