FUNCTION Procedures
FUNCTION procedures provide a powerful alternative to DEF FN functions.
FUNCTION procedures, like DEF FN functions, are used in expressions and
directly return a single value.
There are, however, important differences. A FUNCTION procedure
- passes values by reference, so it can return additional values by
changing variables in its argument list.
- is not part of the module-level code.
- can be used recursively - it can call itself.
- may be used outside the module in which it is defined. You must include
a DECLARE statement if you use a FUNCTION defined in another module.
QuickBASIC automatically generates DECLARE statements for FUNCTION
procedures defined and used in the same module. You can also enter the
DECLARE yourself:
DECLARE FUNCTION Log10(X)
INPUT "Enter a number: ",Num
PRINT "10 ^ Log10(";Num;") is" 10.0^Log10(Num)
END
' Function to find log base 10 of a number using
' BASIC's built-in natural logarithm function.
FUNCTION Log10 (X) STATIC
Log10 = LOG(X) / LOG(10.0)
END FUNCTION
See Also