HTBasic Help
×
Menu
Index

CALL

Starts execution of specified SUBprogram or CSUB.
 
 [ CALL ] subprogram-name [(argument [,argument...])]
CALL sub-pointer [WITH (argument [,argument...])]
 
Where:
sub-pointer = string expression with subprogram name
argument = pass-by-reference  |  pass-by-value
pass-by-reference = @io-path  |  variable-name[$][ (*) ]  | string-array-element  |  numeric-array-element
pass-by-value = ( variable-name[$] )  |  numeric-constant  | numeric-expression  |  ( numeric-array-element )  |
  "string-literal"  | string-name$[(subscripts)]sub-string| string-expression  |  ( string-array-element )
 
Usage:
CALL Deriv(X,Y)
Fft(Array(*))
CALL Test(Ref,(Value),@Source)
CALL A$ WITH (4,1.23,"hello")
 
Example:      CALL.BAS
 
Description:
CALL transfers control to the specified SUBprogram. The context is changed to the SUB and begins running at the statement following the SUB statement. The subprogram continues to run until it encounters a SUBEND or SUBEXIT, at which point control returns to the statement after the CALL. If more than one SUB exists with the same name, control is transferred to the SUB with the lowest line number. The name of the SUB may be specified explicitly or in a string expression (sub-pointer):
 
CALL Clayton ! Explicit
CALL "Clay"&"ton" ! String expression
 
CALL may also pass arguments to the subprogram. The list of arguments in the CALL statement must match, in type and number, the list of parameters in the SUB statement. The CALL statement may pass the arguments by reference or value as shown in the syntax description above. Pass-by-value means that the subprogram receives only the value and cannot change any variables in the calling subprogram. Pass-by-reference means that the subprogram is told the variable's location in memory (the variable's address), so that the subprogram can use and modify the variable itself.
 
The CALL keyword may be omitted if the CALL statement is alone on a line and the subprogram name is specified explicitly, but if it is part of another statement, such as an IF, then it is required.
 
Subprogram Pointers
If a string expression specifies the subprogram name in the CALL statement, the string expression is called a subprogram pointer because it "points" to the subprogram rather than explicitly naming it. As the expression changes, the pointer points to different subprograms. The following example illustrates how this can be useful.
 
SUB Xform(X(*))
   Method$="Xform"&VAL$(RANK(X))
   IF NOT INMEM(Method$) THEN LOADSUB Method$
   CALL Method$ WITH(X(*))
   DELSUB Method$
SUBEND
 
The CALL keyword must be used and the subprogram must be specified with the initial character in uppercase and subsequent characters in lowercase. Subprogram pointers can also be used in DELSUB, INMEM, LOADSUB and XREF statements.
 
Note: If you must write programs portable back to HP BASIC, don't use subprogram pointers in DELSUB, LOADSUB, and XREF statements. Also, HTBasic allows string expressions to be used, while HP BASIC is limited to a simple string variable.
 
See Also: