
68
5.3 User-defined Functions
Out of user-defined functions, the
SUB
and
FUNCTION
functions can be called from other
files. The
DEF
FN
function can be called only in the file where that function is defined and
should start with an
FN
.
The
DEF
FN
and
FUNCTION
functions are classified into three types: integer functions, real
functions, and character functions, each of which should be defined in the following format:
■
Setting Character String Length of Returned Values of Character Functions
A character function may return 1 through 255 characters. Note that the default character
string length results in the returned value of 40 characters.
If the returned value of the character string length is always less than 40 characters, you can
use the stack efficiently by setting the actual required value smaller than the default as the
maximum length. This is because the Interpreter positions returned values on the stack during
execution of user-defined functions so as to occupy the memory area by the maximum length
size. To define a function which results in the returned value of one character, for example,
describe as follows:
DEF FNshort$(i%)[1]
On the other hand, if the returned value is more than 40 characters, it is necessary to set the
actually required length. To define a function which results in the returned values of 128 char-
acters, for example, describe as follows:
DEF FNlong$(i%)[128]
■
Dummy Arguments and Real Arguments
Dummy arguments are used for defining user-defined functions. In the example below,
i%
is a
dummy argument.
DEF FNfunc%(i%)
FNfunc%=i%*5
END DEF
Real arguments are actually passed to user-defined functions when those functions are called.
In the example below,
3
is a real argument.
PRINT FNfunc%(3)
User-defined Function
Format of
DEF
FN
Format of
FUNCTION
Integer functions
FN
functionname %
Real functions
FN
functionname
Character functions
FN
functionname $
Содержание BHT-BASIC 100 SERIES
Страница 1: ......
Страница 161: ...153 Chapter 10 Sleep Function CONTENTS 10 1 Sleep Function 154...
Страница 163: ...155 Chapter 11 Resume Function CONTENTS 11 1 Resume Function 156...
Страница 173: ...165 Chapter 13 Backlight Function CONTENTS 13 1 Backlight Function 166...
Страница 192: ...Chapter 14 Statement Reference 184 Example OPEN master Dat AS 1 FIELD 1 20 AS bar 10 AS ky CLFILE 1 CLOSE 1...
Страница 249: ...241 Example CLOSE IF kyIn Y THEN KILL Master Dat END IF Reference Statements CLFILE...
Страница 349: ...341 Run time errors Error code Meaning 05h Parameter out of the range checktype is out of the range...
Страница 383: ...375 Run time errors Reference Error code Meaning 05h Parameter out of the range Functions LEFT LEN and RIGHT...