Microsoft KB Archive/36395
Article ID: 36395
Article Last Modified on 11/21/2006
- Microsoft QuickBasic 1.02
- Microsoft QuickBasic 2.0
- Microsoft QuickBasic 2.01
- Microsoft QuickBasic 3.0
- Microsoft QuickBasic 4.0
- Microsoft QuickBASIC 4.0b
- Microsoft QuickBasic 4.5 for MS-DOS
- Microsoft BASIC Compiler 6.0
- Microsoft BASIC Compiler 6.0b
- Microsoft BASIC Professional Development System 7.0
- Microsoft BASIC Professional Development System 7.1
- Microsoft GW-BASIC 3.2
- Microsoft GW-BASIC 3.22
- Microsoft GW-BASIC 3.23
- Microsoft QuickBasic Compiler for Macintosh 1.0
- 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 Q36395
If you want to append a comment [using REM or an apostrophe (')] to a DATA statement, you must put a colon (:) in front of the REM or apostrophe on the DATA line.
This information applies to QuickBASIC Versions 1.00, 1.02, 2.00, 2.01, 3.00, 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; Microsoft BASIC PDS Version 7.00 for MS-DOS and MS OS/2; to GW-BASIC Versions 3.20, 3.22, and 3.23 for MS-DOS; to QuickBASIC Version 1.00 for the Apple Macintosh; to Microsoft BASIC Interpreter Versions 1.00, 1.01, 2.00, 2.10, and 3.00 for the Apple Macintosh; and to Microsoft BASIC Compiler Version 1.00 for the Apple Macintosh. It may also apply to other versions of Microsoft BASIC not listed here.
In QuickBASIC for MS-DOS, in Microsoft BASIC Compiler for MS-DOS and MS OS/2, and in GW-BASIC for MS-DOS, a READ statement that is accepted into a non-string variable produces a "Syntax error" if it encounters a comment [a REM or an apostrophe(')] without a preceding colon (:) in a DATA statement line.
In QuickBASIC for Macintosh, you get a "Type Mismatch" error if you READ the comment (without a preceding colon) into a non-string variable when you run the program.
In all above versions of BASIC (for all operating systems), the READ statement treats the comment as additional string data for input when it reads into a string variable.
Separating the DATA statement from the REM (or apostrophe) with a colon (:) lets the program run correctly, as in the following example:
DATA abc,,def: rem The second item is null. DATA 1,,2: ' The second item is null. READ a$, b$, c$ ' Note that b$ is assigned to null string ("") PRINT a$, b$, c$ PRINT READ d, e, f ' Note that e is assigned to 0 PRINT d, e, f END
In the following program, the first READ statement reads the DATA statement's comment into c$ along with the last element ("def") of the DATA statement, which is not what the programmer may have wanted. The second READ statement produces a "Syntax error" in QuickBASIC, the BASIC compiler, and GW-BASIC for MS-DOS, and produces "Type Mismatch" in QuickBASIC and BASIC for the Apple Macintosh when it attempts to mistakenly read a (string) comment into a numeric variable:
DATA abc,,def rem The second item is null. [This becomes data.] DATA 1,,2 ' The second item is null. [This becomes data.] READ a$, b$, c$ ' Note that b$ is assigned to null string ("") PRINT a$, b$, c$ PRINT READ d, e, f ' This READ gives error while reading in f. PRINT d, e, f END
Additional query words: QuickBas BasicCom MQuickB