Download BL600 smartBASIC Module

Transcript
smart BASIC
User Manual
When a value is passed by value to a routine, any modifications to that variable will not reflect
back to the calling routine. However, if a variable is passed by reference then any changes in
the variable will be reflected back to the caller on exit.
The SUB statement marks the beginning of a block of statements which will consist of the body of
a user routine. The end of the routine is marked by the ENDSUB statement.
ENDSUB
This statement marks the end of a block of statements belonging to a subroutine. It MUST be
included as the last statement of a SUB routine, as it instructs the compiler that there is no more
code for the SUB routine.
Note that any variables declared within the subroutine lose their scope once ENDSUB is
processed.
EXITSUB
This statement provides an early run-time exit from the subroutine.
FUNCTION
A statement beginning with this token marks the beginning of a block of statements which will
consist of the body of a user routine. The end of the routine is marked by the ENDFUNC
statement.
A function is a block of statements which constitute a user routine that returns a value. A
function takes arguments, and can return a value of type simple or complex.
FUNCTION routinename (arglist) AS vartype
EXITFUNC arithemetic_expression_or_string_expression
ENDFUNC arithemetic_expression_or_string_expression
A Function MUST be defined before the first instance of its being called. It is good practice to
define subroutines and functions at the beginning of an application, immediately after variable
declarations.
A typical example of a function block would be
FUNCTION somename(arg1 AS INTEGER arg2 AS STRING) AS INTEGER
DIM S AS INTEGER
S = arg1
IF arg1 == 0 THEN
EXITFUNC arg1*2
ENDIF
ENDFUNC arg1 * 4
Defining the routine name
The function name can be any valid name that is not already in use. The return variable is
always passed as byVal and shall be of type varType.
Return values are defined within zero or more optional EXITFUNC statements and ENDFUNC is
used to mark the end of the block of statements belonging to the function.
www.lairdtech.com
150
Laird Technologies