CONST, DATA Cannot Precede COMMON Statement (27254)



The information in this article applies to:

  • Microsoft QuickBASIC 4.0, when used with:
    • the operating system: MS-DOS
  • Microsoft QuickBASIC 4.0b, when used with:
    • the operating system: MS-DOS
  • Microsoft QuickBASIC 4.5, when used with:
    • the operating system: MS-DOS
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0
  • Microsoft BASIC Compiler for MS-DOS and OS/2 6.0b
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.0
  • Microsoft Basic Professional Development System (PDS) for MS-DOS and MS OS/2 7.1

This article was previously published under Q27254

SUMMARY

BC.EXE correctly gives the error message "COMMON and DECLARE must precede executable statements" 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 "nonexecutable" nature of DATA and CONST statements):
  1. Page 116 of the "Microsoft QuickBasic 4.0: Basic Language Reference" for versions 4.00 and 4.00b
  2. Pages 64 and 637 of the "Microsoft Basic 7.0: Basic Language Reference" 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 "Microsoft QuickBasic 4.0: Basic Language Reference" (for versions 4.00 and 4.00b), and on page 397 of the "QuickBasic 4.5: Programming in Basic" 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 "COMMON out of order" 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
				

Modification Type:MinorLast Reviewed:1/8/2003
Keywords:KB27254