63
TIDE and Tibbo BASIC User Manual
©2000-2008 Tibbo Technology Inc.
dim
a(
10
)
as
byte
' a is a global variable -- outside the scope of the
function.
sub
init_array
dim
i
as
integer
for
i =
0
to
9
a(i) =
0
' the global variable gets changed.
next
i
end
sub
Subs change the value of the arguments passed to them using
and thus
indirectly return a value, or even several values. Of course, they may also change
the value of global variables.
Event handlers are like subs
Event handlers defined in the platform work exactly like sub procedures. Event
handler subs can accept arguments. Event handlers can never be function
procedures as each function has to return a value and the event handler has
nobody to return this value to.
Declaring Procedures
Usually, a procedure is first defined by the
or
statements and
then used in code; however, at times, functions can reside in a different
compilation unit. In such a case, you must use the
modifier when
defining this function, and use the
to let the compiler
know that the function exists.
For example, let us say this is the file utility_functions.tbs:
public
function
multiply(a
as
integer
, b
as
integer
)
as
integer
' the
value returns by this function is an integer
multiply = a * b
end
function
And this is the file program.tbs:
declare
function
multiply(a
as
integer
, b
as
integer
)
as
integer
'
declaring just the name isn't enough. Include also the arguments and the
types.
dim
i
as
integer
i = multiply(
3
,
7
)
Declare statements are usually used within header files which are then included
into compilation units. Also, if for some reason you would attempt to use a
procedure in a single compilation unit before defining it, you will have to use a
declare statement to let the compiler know that it exists. For example:
64
87
93
98
79
79