How to Use REM or ' Comments in DATA Statements without Error (36395)
The information in this article applies to:
- 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
- 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
- Microsoft GW-BASIC 3.2
- Microsoft GW-BASIC 3.22
- Microsoft GW-BASIC 3.23
- Microsoft QuickBASIC Compiler for the Apple Macintosh 1.0
- 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 Q36395 SUMMARY
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.
MORE INFORMATION
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.
Correct Example
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
Incorrect Example
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
Modification Type: | Minor | Last Reviewed: | 1/9/2003 |
---|
Keywords: | KB36395 |
---|
|