Microsoft KB Archive/27254

= CONST, DATA Cannot Precede COMMON Statement =

Article ID: 27254

Article Last Modified on 11/21/2006

-

APPLIES TO


 * Microsoft QuickBasic 4.0, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBASIC 4.0b, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft QuickBasic 4.5 for MS-DOS, when used with:
 * Microsoft MS-DOS 6.22 Standard Edition
 * Microsoft BASIC Compiler 6.0
 * Microsoft BASIC Compiler 6.0b
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q27254



SUMMARY
BC.EXE correctly gives the error message &quot;COMMON and DECLARE must precede executable statements&quot; if DATA and CONST statements are placed before COMMON statements. However, the QB.EXE or QBX.EXE environment fails to give this error in the same situation, and actually runs the program. Despite this behavior of QB.EXE and QBX.EXE, DATA and CONST statements should only be placed after COMMON statements in your source code.

This information applies to Microsoft QuickBasic versions 4.00, 4.00b, and 4.50 for MS-DOS; to Microsoft Basic Compiler versions 6.00 and 6.00b for MS-DOS and MS OS/2; and to Microsoft Basic Professional Development System (PDS) versions 7.00 and 7.10 for MS-DOS and MS OS/2.



MORE INFORMATION
The manuals below correctly say that DATA and CONST are nonexecutable statements, but the manuals need to mention that COMMON statements must be placed before all DATA and CONST statements (despite the &quot;nonexecutable&quot; nature of DATA and CONST statements):
 * 1) Page 116 of the &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; for versions 4.00 and 4.00b
 * 2) Pages 64 and 637 of the &quot;Microsoft Basic 7.0: Basic Language Reference&quot; for Basic PDS versions 7.00 and 7.10
 * 3) The online Help for the COMMON statement, under Details, in QB.EXE version 4.50, and QBX.EXE versions 7.00 and 7.10

On page 481 of the &quot;Microsoft QuickBasic 4.0: Basic Language Reference&quot; (for versions 4.00 and 4.00b), and on page 397 of the &quot;QuickBasic 4.5: Programming in Basic&quot; manual, CONST and DATA (along with STATIC and SHARED) are missing from the list of nonexecutable statements, but the given list still correctly shows statements that ARE allowed before COMMON statements (plus STATIC and SHARED statements are also allowed before COMMON statements).

Note that QuickBasic version 3.00 correctly gives the error message &quot;COMMON out of order&quot; when CONST or DATA statements precede COMMON, whether compiled in the QB.EXE editor or from the QB command line.

All you need to remember is to put DATA and CONST statements after COMMON statements (if any).

The following code example demonstrates the error message: DECLARE SUB one DATA 999 CONST max = 99 COMMON z         ' BC.EXE's error message occurs on this line. ' Must move DATA and CONST to be after the COMMON. mytest = 7 CALL one END SUB one SHARED z READ x  PRINT z, max, x END SUB 'Run-time output inside editor:  7      99      999

Additional query words: QuickBas BasicCom

Keywords: KB27254

-

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

© Microsoft Corporation. All rights reserved.