81
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
Example
declare
function
hittest(x
as
integer
, y
as
integer
)
as
boolean
declare
sub
dosomething (s
as byref
string
)
declare
devicestate
as
integer
Dim Statement
Function:
Defines a variable and allocates memory for it.
Syntax:
[ public ] dim name1 [ (bounds1) ] [ , name2 [
(bounds2) ] ]
as type [ (max_string_size) ]
Scope:
Global, HTML and local
See Also:
Part
Description
public
Optional; may only be used in a global scope. If present,
makes the variable(s)
.
name[1, 2...]
Required. Specifies the name for the variable.
bounds[1, 2...]
Optional. Specifies the boundary (finite size) of a dimension
in an array. Several comma-delimited boundary values
make a multi-dimensional array.
as
Required. Precedes the type definition.
type
Required. Specifies the
of the variable.
max_string_size
Optional (can be used only when type is string). Sets the
maximum size for a string (default size is 255 bytes).
Details
The dim statement creates a variable in the current scope. It reserves memory
space for this variable. Hence, as part of a dim statement, you have to specify the
type of the variable; specifying the type also defines how much memory will be
allocated for this variable.
When creating strings, you can explicitly define their maximum size by including it
in parentheses immediately following the string keyword. The default maximum
size of strings is 255 bytes, but if you're sure a string will contain less than 255
bytes of data, it is better to constrain it to a lower size (and thus reduce the
memory footprint of your program).
The dim statement can also be used to create
. This is done by specifying
the number of elements in the array in parentheses immediately following the
name of the variable. Multi-dimensional arrays are created by specifying the
number of elements in each dimension, separated by commas.
Note that creating a variable using dim does not assign any value (i.e, 0) to this
variable.
There are alternative ways of specifying the number and size of each array
79
57
43
50