Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
DEF FN Functions
◄Scope Rules► ◄Variables► ◄Contents► ◄Index► ◄Back►
─────────────────────────────────────────────────────────────────────────────
DEF FN Functions
The DEF FN is an exception to the BASIC scoping rules. Every variable in a
DEF FN function that isn't in its parameter list is part of the module-
level code. In order to make a variable local to a DEF FN, you must declare
the variable in a STATIC statement. The STATIC statement in the following
DEF FN function makes the variable I local:
CONST NO = 0, YES = NOT NO
DEF FNIsThereAZ (A$)
STATIC I
FOR I = 1 TO LEN(A$)
IF UCASE$(MID$(A$, I, 1)) = "Z" THEN
FNIsThereAZ = YES
EXIT DEF
END IF
NEXT I
FNIsThereAZ = NO
END DEF
Remember, as a general rule, a FUNCTION is preferred over a DEF FN because
of its improved portability, increased modularity, and more structured
programming style.