HTBasic Help
×
Menu
Index

SUB

Defines a subprogram and specifies formal parameters.
 
 SUB subprogram-name [ (parameter-list) ]
statements
[SUBEXIT]
statements
SUBEND
 
 
 
 
Usage:
SUB Unit1
SUB Link(String$)
SUB Procm(INTEGER Array(*),OPTIONAL @Lpr,Name$)
SUB Plot(Buff$ BUFFER,Coor)
Example: SUB.BAS
Description:
SUB subprograms must follow the MAIN program's END statement. The first line must be a SUB statement and the last line a SUBEND statement. The lines between SUB and SUBEND statements define a subprogram which can be called by other parts of the program with the CALL statement.
Unless the OPTIONAL keyword is specified, the number of CALL arguments must match the number of SUB parameters; each argument must be of the same type (numeric or string) as the corresponding parameter. Any parameters to the right of the OPTIONAL keyword are optional in the CALL statement. NPAR returns the number of arguments in the current CALL statement. All variables defined in a subprogram that are not COM variables are local to the subprogram. Upon each entry to the subprogram they are set to zero.
A CALL to a subprogram, transfers control to the first statement of that subprogram and starts executing from there. Execution proceeds normally until either a SUBEND or SUBEXIT statement is executed, at which point control returns to the statement after the CALL. The SUBEXIT statement allows a return from the subprogram at points other than the SUBEND. Multiple SUBEXITs are allowed in a subprogram. SUBEXIT may appear in an IF statement, SUBEND can not.
See Also: