Section 3.7
Programming In QuickBASIC
3.7 Subprograms
A subprogram is a structure that enables a large program to be broken down into smaller
parts, each doing a specific job.
A subprogram may not contain parameters although it usually will.
DECLARE SUB <subprogram name>
- - -
- - -
CALL <subprogram name>
- - -
- - -
END
SUB <subprogram name>
   - - -
   - - -
   - - -
END SUB
A subprogram may be called any number of time from the main program or another sub.
A sub can be exited any time with EXIT SUB
.
READ
statements may appear in a subprogram but not DATA
statements, which should remain at the end of the main body.
If we wish to use a variable in a subprogram that we've assigned a value in the main
body and it must be passed to the subprogram, we must use parameters.
DECLARE SUB <subprogram name> (Formal Parameters)
- - -
- - -
CALL <subprogram name> (Parameters)
- - -
- - -
END
SUB <subprogram name> (Formal Parameters)
   - - -
   - - -
   - - -
END SUB
The formal parameters and the list of parameters must be equal in number and of respective
data type (although they may not have the same name).
3.7.3 Passing By Value
If the CALL
statements contain certain literal values such as numbers or string
literals then these values are said to be "passed by value" to the subprogram.
3.7.4 Passing By Reference
If the variable name in a formal paramter does not match the variable name in a list of
parameters, then the variable in the list of parameters adopts the ability to refer to the same
memory location as the variable in the formal parameters.