HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)

3- 37
A function is edited using the procedures described in chapter 2.
A program unit calls a multi-line function the same way it calls a
predefined or single-line function: by its name, followed by an actual
parameter list if it has one. The list of actual parameters is enclosed
in parentheses, and the individual parameters are separated by commas.
Example
10 READ A,B !Main program begins
15 DATA 48, 50
20 C$=FNFunc$(A,B) !Main program calls FNFunc$; go to line 100
30 PRINT C$
99 END !Main program ends
100 DEF FNFunc$(X,Y) !Function FNFunc$ begins
105 DIM String$[1]
115 String$=CHR$(X+Y)
120 RETURN String$ !FNFunc$ returns value to line 20
999 FNEND !Function FNFunc$ ends
A multi-line function can also be called as a subprogram with the CALL
statement. In this case, the value returned by the function is
discarded.
If a program has more than one subunit with the same name, the name
references the first subunit that it finds. The following is the search
order:
1. Single-line function.
2. Local external or intrinsic subunit.
3. Internal multi-line function (one defined by the program).
4. Global external or intrinsic subunit.
Parameter Passing
An actual parameter can be passed to a subprogram by reference or by
value. Actual parameters are passed by reference unless the individual
actual parameter is enclosed in parentheses or is an expression or
substring. Enclosing the actual parameter in parentheses specifies that
the actual parameter is to be passed by value.
Table 3-29 compares the two methods. String or numeric literals are
always passed by value. Arrays are always passed by reference.
Table 3-29. Parameter Passing Methods
---------------------------------------------------------------------------------------------
|| | |
||Actual Parameter | Actual Parameter |
||Passed by Reference | Passed by Value |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Formal parameter | The actual parameter itself. | Assigned the value of the actual |
| is | | parameter. |
|| | |
---------------------------------------------------------------------------------------------
|| | |
| Subprogram can | If it changes corresponding formal | No. |