Hardware Reference
In-Depth Information
It should be noted that the QuickBASIC editor will recognize the SUB state-
ment and will treat the procedure as a separate subprogram (with an automatic
declaration inserted at the start of the main program code). Thereafter, the
subprogram can be viewed and edited independently of the main program code.
The method of calling the delay procedure is more elegant than that used
with the equivalent subroutine and takes the following format:
REM Start of main program
DECLARE SUB Delay(lim%)
...
...
CALL Delay(10000)
...
...
CALL Delay(20000)
...
...
CALL Delay(15000)
...
...
The values within parentheses are parameters passed into the procedure as
lim% . Such values are local to the procedure and external references to lim% will
remain unchanged by the action of the procedure. It should also be noted that
an overflow error will occur if values passed into the subprogram should ever
exceed 32 766. Longer delays can be produced using floating point variables,
as follows:
REM Delay procedure
SUB Delay(lim)
FORc=0TOlim: NEXT c
END SUB
while the relevant code in the main program should run along the following lines:
REM Start of main program
DECLARE SUB Delay(lim)
...
...
CALL Delay(10000)
...
...
CALL Delay(20000)
...
...
CALL Delay(15000)
...
...
Since we are using floating point variables, values passed into the subprogram
can now exceed the 32 766 limit imposed on integers (see Table 6.1 for details).
User-defined functions
User-defined functions are similar to user-defined procedures but return values
(integer, float, or string) to the main program. As with user-defined procedures,
functions are called by name (or FN name ). An example of a user-defined
function ( FNConfirm% ) appears later in this chapter.
Search WWH ::




Custom Search