Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
CHAIN Statement Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses the COMMON statement to pass variables between two
' chained programs. It uses the CHAIN statement in the first program
' (PROG1) to load and run a second program (PROG2), which finds and prints
' the average of the values.
' Note: After running this example from the programming environment, you
' will be left in PROG2.BAS.
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
DIM values(1 TO 50) ' Set up the variables that are
COMMON values(), NumValues% ' passed from PROG1 to PROG2
' The following lines of code create the second program on disk so that it
' can load and run with the CHAIN statement. It is, in fact, a series of
' PRINT # statements that puts the proper Basic statements in a file.
CLS ' Clear the screen
OPEN "PROG2.BAS" FOR OUTPUT AS #1
PRINT #1, "' This is PROG2 for the CHAIN and COMMON statement examples."
PRINT #1, " DIM X(1 TO 50)"
PRINT #1, " COMMON X(), N%"
PRINT #1, " PRINT"
PRINT #1, " IF N% > 0 THEN"
PRINT #1, " Sum% = 0"
PRINT #1, " FOR I% = 1 TO N%"
PRINT #1, " Sum% = Sum% + X(I%)"
PRINT #1, " NEXT I%"
PRINT #1, " PRINT "; CHR$(34); "The average of the values is";
PRINT #1, CHR$(34); "; Sum% / N%"
PRINT #1, " END IF"
PRINT #1, " END"
CLOSE #1 ' End of PROG2 creation section
CLS ' Clear the screen
PRINT "Enter values one per line. Type 'END' to quit."
NumValues% = 0
DO
INPUT "-> ", N$
IF I% >= 50 OR UCASE$(N$) = "END" THEN EXIT DO
NumValues% = NumValues% + 1
values(NumValues%) = VAL(N$)
LOOP
PRINT "Press any key to continue... "
DO WHILE INKEY$ = ""
LOOP
CHAIN "PROG2.BAS"
END