HP Business BASIC/XL Reference Manual - HP 3000 MPE/iX Computer Systems - Edition 1 (32715-90001)
3- 36
Syntax
SUB_stmt
[
stmt
]...
SUBEND_stmt
Parameters
SUB_stmt
SUBPROGRAM or SUB statement. Not executable. Indicates
that the lines that follow are a subprogram.
stmt
Can be a SUBEXIT statement that returns control to the
calling program unit before the SUBEND statement is
executed, or can be any executable statement. These
statements constitute the body of the subprogram.
SUBEND_stmt
SUBEND statement. Indicates the end of the subprogram.
A subprogram follows the editing procedure described in chapter 2.
A program unit calls a subprogram with a CALL statement. The subprogram
returns control to the statement following the CALL statement.
Example
10 READ A,B !Main program begins
15 DATA 48,50
20 CALL Sub1(A,B) !Main program calls Sub1; go to line 100
30 PRINT A
40 PRINT B
99 END !Main program ends
100 SUB Sub1 (X,Y) !Subprogram Sub1 begins
105 DIM String$[1]
110 IF X<0 THEN SUBEXIT !If X<0, Sub1 ends early; go to line 30
115 String$=CHR$(X+Y) !If X=>0, Sub1 continues
120 PRINT String$
999 SUBEND !Subprogram Sub1 ends; go to line 30
User-Defined Multi-Line Functions
A user-defined multi-line function is a subunit that returns a value to
the calling program unit. The value returned by a function has a
specific type. A function that returns a numeric value is called a
numeric function; A function that returns a string value is called a
string function.
Syntax
DEFFN_stmt stmt
[
stmt
] . . .
FNEND_stmnt
Parameters
DEFFN_stmnt
DEF FN statement. Not executable. Indicates that the
lines that follow are a multi-line function.
stmt
Executable statements that make up the body of the
function. At least one
stmt
must be a RETURN statement
that returns a value and control to the calling program
unit.
FNEND_stmt
FNEND statement. Indicates the end of the function.