WRITE# Statement Works with Semicolon Despite BC.EXE Error (34610)



The information in this article applies to:

  • 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

This article was previously published under Q34610

SUMMARY

Microsoft does not recommend linking object modules that produced one or more severe error messages at compile time. The behavior of such programs cannot be guaranteed to work in future product versions, or even to work at all.

An example is shown below for the case of improperly using a WRITE# statement with a trailing semicolon with the intent to suppress a carriage return. PRINT# is intended for this purpose, not WRITE#.

MORE INFORMATION

According to Page 455 of the "Microsoft QuickBasic 4.0: Basic Language Reference" manual for QuickBasic Versions 4.00 and 4.00b, the WRITE# statement should not allow a semicolon at the end of its arguments. QB.EXE correctly displays an "Expected:Expression" error message on the WRITE# statement at run time. A "Syntax Error" is correctly produced when the BC.EXE compiler tries to compile the following program, which has a semicolon at the end of a WRITE statement:
open "data" for output as #1
write #1, str$(5);    ' This line is not allowed to have a ";"
write #1, str$(5)
close #1
				
Despite the "severe" error message at compile time, BC.EXE produces an object module that can be linked into an executable program. This program executes as you might expect a WRITE# with a semicolon at the end to work (i.e., no carriage return or linefeed). However, this behavior cannot be guaranteed for future versions.

Note that the PRINT# statement can be used in place of the WRITE# statement if you wish to use a trailing semicolon to suppress the carriage return, as shown in the following program:
open "data" for output as #1
PRINT#1, CHR$(34) + STR$(5) + CHR$(34) + ", ";    'This is allowed.
write #1, str$(5)
close #1
				
The WRITE# statement delimits output arguments with commas, and also places double quotation marks around string arguments.

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