Please enable JavaScript to view this site.

A-Shell Reference

Navigation: Development Topics > SBX Subroutines

External (XFUNC) Functions

Scroll Prev Top Next More

XFUNC and XFUNC$ provide a means of calling external subroutines as if they were functions.

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$).

See Also