SUB procedurename[(arglist)]
[statements]
[EXIT SUB]
[statements]
END SUB
Description
SUB declares a procedure, procdurename, that executes statements, with arglist as parameters, with no return value. The required parameter, procedurename, is used to call the procedure, and must follow standard variable naming conventions. The optional parameter list, arglist, is a comma separated list of variables that are passed to the procedure when it is called. The optional component, statements, will be executed as the body of the procedure. Any number of optional EXIT SUB statements can be used to exit the procedure.
Each member of arglist is an argument passed to the procedure, as declared below:
[BYVAL | BYREF] varname[()]
The optional keyword, BYVAL, specifies that a copy of the variable be passed into the procedure, making its value outside the procedure unmodifiable by the procedure. The optional keyword, BYREF, specifies that the address of the variable be passed into the procedure, making its value outside the procedure modifiable by the procedure. By default, parameters are passed in BYREF.
A FUNCTION procedure will be called as a SUB procedure if the return value is not stored in a variable or used in an expression.
A SUB procedure called with zero or one arguments may be called with empty parenthesis or the single argument in parenthesis. NS Basic/CE treats a single expression enclosed in parenthesis as a single expression, not a one-element argument list.
Example
REM SUB Example
'SUB declares a procedure
DIM PriceA, PriceB
PrintMenu "Wednesday"
PriceA = 53
PriceB = 44
Sort PriceA, PriceB
PRINT "Lowest Price:", PriceA
SUB PrintMenu(day)
IF day = "Wednesday" THEN
PRINT "Wednesday is Salisbury Steak day"
END IF
END SUB
SUB Sort(BYREF x, BYREF y)
DIM Temp
IF x > y THEN
Temp = y
y = x
x = Temp
EXIT SUB
ELSE
Temp = x
x = y
y = Temp
END IF
END SUB
Output
Wednesday is Salisbury Steak day
Lowest Price:44
Related Items
CALL, FUNCTION