
Chapter 14. Statement Reference
322
Description:
■
Creating a user-defined function
SUB
...
END
SUB
creates a user-defined function. The function definition block
between
SUB
and
END
SUB
is a set of some statements and functions.
• You cannot make double definition to a same function name.
• This statement block should not be defined in the block-structured statements
(
DEF
FN
...
END
DEF
,
FOR
...
NEXT
,
FUNCTION
...
END
FUNCTION
,
IF
...
THEN
...
ELSE
...
END
IF
,
SELECT
...
CASE
...
END
SELECT
,
SUB
...
END
SUB
, and
WHILE
...
WEND
), in the error-handling routine, event-handling routine, or in the
subroutines.
•
SUB
...
END
SUB
functions can be recursive.
•
dummyparameter
, which corresponds to the variable having the same name in
the function definition block, is a local variable valid only in that block. Therefore,
if a variable having the same name as
dummyparameter
is used outside
SUB
...
END
SUB
statement block or used as a
dummyparameter
of any other
function in the same program, then it will be independently treated.
• In user-defined functions, you can call other user-defined functions. You can nest
SUB
...
END
SUB
statements to a maximum of 10 levels.
• When using the
SUB
...
END
SUB
together with block-structured statements (
DEF
FN
...
END
DEF
,
FOR
...
NEXT
,
FUNCTION
...
END
FUNCTION
,
IF
...
THEN
...
ELSE
...
END
IF
,
SELECT
...
CASE
...
END
SELECT
,
SUB
...
END
SUB
, and
WHILE
...
WEND
), you can nest them to a maximum of 30 levels.
• If variables other than
dummyparameter
(s) are specified in the function defini-
tion block, they will be treated as local variables whose current values are avail-
able only in that function definition block, unless
PRIVATE
or
GLOBAL
statement
is used.
•
EXIT
SUB
exits the function block prematurely and returns control to the position
immediately after the statement that called the user-defined function.
• Unlike other user-defined functions,
SUB
function cannot assign a return value.
■
Calling a user-defined function
CALL
statement and
subname
call a user-defined function.
CALL
can be omitted.
• The number of
realparameter
s should be equal to that of
dummyparame-
ter
s, and the types of the corresponding variables used in those parameters
should be identical.
• If you specify a global variable in
realparameter
when calling a user-defined
function, the user-defined function cannot update the value of the global variable.
This is because all
realparameter
s are passed not by address but by value.
(So called "Call-by-value")
Summary of Contents for BHT-BASIC 100 SERIES
Page 1: ......
Page 161: ...153 Chapter 10 Sleep Function CONTENTS 10 1 Sleep Function 154...
Page 163: ...155 Chapter 11 Resume Function CONTENTS 11 1 Resume Function 156...
Page 173: ...165 Chapter 13 Backlight Function CONTENTS 13 1 Backlight Function 166...
Page 249: ...241 Example CLOSE IF kyIn Y THEN KILL Master Dat END IF Reference Statements CLFILE...