Microsoft KB Archive/32220

= COMMON Required/CHAINed Compiled Program, Not Interpreter =

Article ID: 32220

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 1.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Interpreter 1.0
 * Microsoft BASIC Interpreter 1.01 for Macintosh
 * Microsoft BASIC Interpreter 2.0
 * Microsoft BASIC Interpreter 2.1 for Macintosh
 * Microsoft BASIC Interpreter 3.0 for Macintosh

-



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&amp; = 1234567890& C! = 1.2345 D# = 1.23456789# C$ = &quot;string&quot; FOR I=1 TO 3 X(I) = I NEXT I Ext$ = &quot;&quot; IF SYSTEM(4) then Ext$ = &quot; Apl&quot;  ' SYSTEM(4) requires QuickBASIC 1.00. CHAIN &quot;B.BAS&quot; + 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

Additional query words: BasicCom MQuickB

Keywords: KB32220

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.