External (XFUNC) Functions

As of Build 828, A-Shell supports programmable external functions. These are created and act very much like subroutines written in BASIC, except that they return a value and may therefore be used within expressions. Just as external subroutines are accessed via the XCALL (or VXCALL) statement, external functions are accessed via the XFUNC function:

XFUNC(Sbxnam, Arg1, Arg2,..., Argn)

XFUNC$(Sbxnam, Arg1, Arg2,..., Argn)

XFUNC (without the $) is a numeric function (i.e. evaluates to a floating point value), while XFUNC$ is for string functions. Sbxnam is a string expression that evaluates to the name of the SBX module containing the function code. Arg1 through Argn are arbitrary arguments or parameters to the function (analogous to the parameters in a subroutine statement.)

From the standpoint of the calling program, XFUNC() and XFUNC$() may be used within expressions just like any other numeric function or string function, for example:

PRINT XFUNC$("CENTER",Name$,40);

TOTAL = QTY * XFUNC(PriceFunc$,Part$,Cust$,QTY)

The SBX implementation of the function must end with a special version of the RETURN statement which specifies the value to return:

RETURN (<expression>)

The <expression> should be numeric for functions to called by XFUNC, and string for those called by XFUNC$. This form of the RETURN statement will be treated the same as END (i.e. terminate subroutine and return to calling program) if the SBX was called via a subroutine statement.

External functions may also return updated parameter values just like subroutines do. In fact, a single SBX module may act as both an external function and a subroutine routine. The distinction is just in how it is called (via XCALL, XFUNC or XFUNC$).