Chapter
10
I
BASIC Keywords
Sample Program
2
Enter NEW and this program:
10 REM THIS PROGRAM DEMONSTRATES CHAINING USING
20 A$="MAINPROG.BAS"
30 CHAIN MERGE
"overlayl",
1000,
ALL
40 END
THE MERGE AND
ALL
OPTIONS.
Save this program as
mainprog.bas,
using the A option. Enter
NEW, and then type:
1000 PRINT
A$;"
HAS CHAINED TO OVERLAY1
.BAS."
1010
A$
=
"overlayl
.bas"
1020
B$
=
"overlay2.ba5"
1030 CHAIN MERGE
"overlay2.ba5",
1000,
ALL,
1040 END
DELETE 1020
-
1040
Save this program
as
overlayl.bas,
using the A option. Enter
NEW, and then these lines:
1000 PRINT
A$;
"
HAS CHAINED
TO
";E$;"."
1010 END
Save this program
as
overlay2.bas,
using the A option. Load
mainprog.bas
and run it. Your screen should display:
MAINPROG.BAS HAS CHAINED TO OVERLAY1.BAS.
OVERLAY1.BAS HAS CHAINED TO OVERLAY2.BAS.
Hints:
The CHAIN statement with the MERGE option leaves the
files open and preserves the current OPTION BASE setting.
0
The CHAIN statement without the MERGE option does not
preserve variable types or user-defined functions for use by the
chained program. That is, any DEFINT, DEFSNG, DEFDBL,
DEFSTR, or DEF FN statements containing shared variables
must be restated in the chained program.
0
When using the MERGE option, place user-defined functions
before any CHAIN MERGE statements in the program. Oth-
erwise, the user-defined functions will be undefined after the
merge
is
complete.
0
CHAIN automatically executes a RESTORE before running
the chained program. The next READ statement starts at the
first item of the first DATA statement.
110