UniBasic Commands Reference - Rocket Software

UniBasic Commands Reference - Rocket Software UniBasic Commands Reference - Rocket Software

rocketsoftware.com
from rocketsoftware.com More from this publisher
11.04.2013 Views

FUNCTION Syntax FUNCTION function.name [([MAT] arg.1[, [MAT] arg.2]...)] RETURN var Description The UniBasic FUNCTION command begins the definition of a user-written function. The FUNCTION command must be the first noncomment line in the file, which must be cataloged locally or globally. The cataloged file name must be included in the DEFFUN statement in the calling program. The calling program must specify the same number and type of arguments in the calling statement as are included in the FUNCTION statement. Note: UniData triggers are UniBasic subroutines or functions that are called when a user attempts to update or delete a record. For more information about coding a UniBasic function that is called by a trigger, see Developing UniBasic Applications. 1-278 UniBasic Commands Reference

Parameters The following table describes each parameter of the syntax. Parameter Description function.name Specifies the name of the function (for documentation purposes only). It need not be the same as the name used to call the function. You must include this function’s cataloged file name in the DEFFUN statement in the calling program. (MAT arg.1 ,MAT arg.2...) Examples Specifies the arguments to be passed from the calling program. Arguments must be enclosed in parentheses and separated by commas. Precede an argument with MAT to indicate that the argument is an array. Up to 254 arguments can be passed. RETURN var Returns control to the calling program. Can pass back an argument. FUNCTION Parameters The following function performs calculations on a dimensioned array, returning values in the function arguments and return value, r. The name of the cataloged file that contains this function definition is yourfunc. This name must be used in the DEFFUN statement in the calling program. Notice that the function definition uses yet a different name (anotherfunc). The name anotherfunc is not referenced anywhere. FUNCTION anotherfunc(a, MAT b, c) ;* Start function definition. DIM b(-1) ;* Declare array. r = 0 ;* Initialize return value. c = 1 ;* Initialize value passed back. FOR i = 1 TO a ;* To the upper bound passed in: r += b(i) ;* Sum array members. c *= b(i) ;* Multiply array members. NEXT i RETURN r ;* Return value. FUNCTION 1-279

Parameters<br />

The following table describes each parameter of the syntax.<br />

Parameter Description<br />

function.name Specifies the name of the function (for documentation purposes<br />

only). It need not be the same as the name used to call the<br />

function.<br />

You must include this function’s cataloged file name in the<br />

DEFFUN statement in the calling program.<br />

(MAT arg.1 ,MAT<br />

arg.2...)<br />

Examples<br />

Specifies the arguments to be passed from the calling program.<br />

Arguments must be enclosed in parentheses and separated by<br />

commas. Precede an argument with MAT to indicate that the<br />

argument is an array. Up to 254 arguments can be passed.<br />

RETURN var Returns control to the calling program. Can pass back an<br />

argument.<br />

FUNCTION Parameters<br />

The following function performs calculations on a dimensioned array, returning<br />

values in the function arguments and return value, r. The name of the cataloged file<br />

that contains this function definition is yourfunc. This name must be used in the<br />

DEFFUN statement in the calling program. Notice that the function definition uses<br />

yet a different name (anotherfunc). The name anotherfunc is not referenced<br />

anywhere.<br />

FUNCTION anotherfunc(a, MAT b, c) ;* Start function<br />

definition.<br />

DIM b(-1) ;* Declare array.<br />

r = 0 ;* Initialize return value.<br />

c = 1 ;* Initialize value passed<br />

back.<br />

FOR i = 1 TO a ;* To the upper bound passed<br />

in:<br />

r += b(i) ;* Sum array members.<br />

c *= b(i) ;* Multiply array members.<br />

NEXT i<br />

RETURN r ;* Return value.<br />

FUNCTION 1-279

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!