QuickBasic syntax
In version 2.xx and above, Superbase introducted the support
for declaring subroutines, functions, and procedures. To rewrite
our simple sample above in QuickBasic syntax, we could do
this:
SUB main()
OPEN FILE SHARE,0"PEOPLE"
OPEN FORM "CONTACT"
SELECT KEY "John Smith"
CALL ring_the_bell( 5 )
END SUB
SUB ring_the_bell ( num_times% )
FOR I% = 1 to num_times%
BELL
NEXT I%
END SUB
In this program, there are two notable items. First is that
the process of ringing the bell has been moved into it's own
SUBroutine, and we have "passed into" the subroutine,
the number of times that we want to ring the bell. This is
the first step towards modularity and reuseability.
The next important advantage of this code, which isn't immediately
apparent is that the variables inside of each subroutines
are LOCAL only to that subroutine. This means that the variables
cannot be "seen", changed, or altered intentionally
or accidentally by other part of the program executing. This
is a HUGE step up from the version 1 style of programming
where ALL VARIABLES ARE GLOBAL.
|