BASIC programs are actually text files. The instructions are read consecutively by the BASIC interpreter. The QBASIC interpreter that comes with DOS is sufficient for our purposes. Sample programs below introduce certain more exotic build-in functions.
Besides the actual code, programs should contain comments with explanations
of instructions and their purpose.
Comments and explanations in the program can be hidden from the processor through
REM command. Everything in a line after this command is skipped (the
only exception being metacommands, which we don't have to concern ourselves with
here).
The sample
programs, use a shortcut '
instead of the full command REM. This is faster to type and equivalent in
action.
The typical program consists of the main module with fairly general instructions that call subroutines to perform specific jobs, and a number of subprograms that are marked in text by SUB ... END SUB, and are displayed separately by the QBASIC Editor. Subprograms make it easier to write, test, and maintain the program.
Within QBasic the
SUBs are separated, each in each own text window, but the final program is saved
as one file with SUBs following the main module.
To create a SUB, choose New SUB from the Edit menu. More details follow in Section
.
Larger
projects often use several modules
that are compiled and run
together.
Every subprogram should begin with a (commented) short description of its purpose, and the meaning of parameters.