COMMON Required/CHAINed Compiled Program, Not Interpreter (32220)
The information in this article applies to:
- Microsoft QuickBASIC 1.0
- Microsoft BASIC Compiler
- Microsoft BASIC Interpreter for Apple Macintosh 1.0
- Microsoft BASIC Interpreter for Apple Macintosh 1.01
- Microsoft BASIC Interpreter for Apple Macintosh 2.0
- Microsoft BASIC Interpreter for Apple Macintosh 2.1
- Microsoft BASIC Interpreter for Apple Macintosh 3.0
This article was previously published under Q32220 SUMMARY
The use of COMMON blocks during a CHAIN operation differs in compiled
programs compared to programs that are run in the interpreter. The
interpreter requires COMMON statements only in the CHAINing program.
Compiled programs require matching COMMON statements in both the
CHAINing and CHAINed programs.
This information applies to Microsoft QuickBASIC Version 1.00, the
Microsoft BASIC Compiler Version 1.00, and the Microsoft BASIC
Interpreter Versions 1.00, 1.01, 2.00, 2.10, and 3.00 for Apple
Macintosh.
MORE INFORMATION
When a program is being interpreted, the names of all variables are
always available, and variables are looked up by name. The CHAINing
program can send all of the variables specified by COMMON statements
to the CHAINed program, which can then look them up by name as it
encounters statements containing variables. Therefore, the interpreter
requires COMMON statements only in the CHAINing program.
Compiled programs do not use variable names. During compilation, names
are translated to addresses, which are stored as part of the object
code. At run time, the addresses are used to manipulate objects
contained at the addresses. Thus, the names are used only at compile
time and are not known at run time. Therefore, unlike the interpreter,
the compiler requires that the same variables be declared in both the
CHAINing and CHAINed programs. The same variables must be declared in
COMMON in exactly the same order in both the CHAINing and CHAINed
programs.
The following program (Program A) assigns values to variables and an
array. It then CHAINs to Program B, which prints out the values.
' Program A
COMMON A%,B&,C!,D#,E$,X(1)
DIM X(3)
A% = 12345
B& = 1234567890&
C! = 1.2345
D# = 1.23456789#
C$ = "string"
FOR I=1 TO 3
X(I) = I
NEXT I
Ext$ = ""
IF SYSTEM(4) then Ext$ = " Apl" ' SYSTEM(4) requires QuickBASIC 1.00.
CHAIN "B.BAS" + Ext$ ' CHAINing to program B.
The following program (Program B) prints out the values of variables
generated in Program A:
' Program B
COMMON A%,B&,C!,D#,E$,X(1) ' THIS STATEMENT IS ONLY REQUIRED FOR
' COMPILED PROGRAMS. IT IS OPTIONAL IF
' USED IN THE INTERPRETER.
PRINT A%,B%,C!,D#,E$
FOR I=1 TO 3
PRINT X(I)
NEXT I
END
Modification Type: | Minor | Last Reviewed: | 8/16/2005 |
---|
Keywords: | KB32220 |
---|
|