Microsoft KB Archive/35244

= To Suppress Linefeed, OPEN &quot;lpt1&quot; BINARY or &quot;LPT1: BIN&quot; RANDOM =

Article ID: 35244

Article Last Modified on 11/21/2006



This article was previously published under Q35244



SUMMARY
When the LPRINT statement sends CHR$(13) (a carriage return) to the printer, it automatically adds a linefeed, CHR$(10). This automatic linefeed prevents the ability to overtype or underline a previously printed line.

The following methods let you suppress the automatic linefeed, as shown in complete programs further below:
 * 1) OPEN &quot;LPT1:BIN&quot; FOR RANDOM AS #n WIDTH#n,255
 * 2) OPEN &quot;lpt1&quot; FOR BINARY #n

[Note that this method requires the &quot;lpt1&quot; device name to have no colon .]

These methods should also be used if you want to send control characters to your printer, such as for printer-graphics mode. Otherwise, the programs below can create garbled graphics output [e.g. the extra linefeed is printed after byte values of 13, and ASCII values of 9 (horizontal tab) are converted to 8 spaces].

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 PDS Version 7.00 for MS-DOS and MS OS/2.



MORE INFORMATION
You cannot suppress the LPRINT statement's linefeed that is automatically sent along with a carriage return. Instead, you must use PRINT#n to send output to special device names as shown in the examples below.

The following programs demonstrate how to print a carriage return (the ASCII character 13) without an automatic linefeed.

Example of Using &quot;LPT1:BIN&quot; Device Name FOR RANDOM Output
OPEN &quot;LPT1:BIN&quot; FOR RANDOM AS #1 WIDTH#1,255 PRINT #1, &quot;This is a test to do underlining.&quot;; PRINT #1, CHR$(13); PRINT #1, &quot;_________________________________&quot;; PRINT #1, CHR$(13); CLOSE #1

Example of Using &quot;LPT1&quot; Device Name FOR BINARY Output
REM This sample program overprints on one line, REM allowing you to underline the text &quot;Seattle Times&quot;. C$ = CHR$(13)        ' 13 = ASCII code for carriage return LPRINT OPEN &quot;lpt1&quot; FOR BINARY AS #1 LPRINT &quot;Seattle Times&quot;; PUT #1,, C$ LPRINT &quot;_______ _____&quot; CLOSE #1 END

Overprinting Using &quot;LPT1:&quot;, &quot;LPT1:BIN&quot;, and &quot;LPT1:&quot; in Sequence
' This works in QuickBasic but not in GW-Basic. ' This program should output the following: ' program output: hello world ' &quot;hello&quot; should print over itself twice. CLS OPEN &quot;lpt1:&quot; FOR OUTPUT AS #1 PRINT #1, &quot;program output: &quot; CLOSE OPEN &quot;lpt1:bin&quot; FOR OUTPUT AS #1 FOR I = 1 TO 3 PRINT #1, CHR$(&HD);   ' Carriage Return with no Line Feed PRINT #1, &quot;hello&quot;; NEXT CLOSE OPEN &quot;lpt1:&quot; FOR OUTPUT AS #1 PRINT #1, &quot; world.&quot; CLOSE PRINT &quot;done printing&quot; END

Additional query words: QuickBas BasicCom

Keywords: KB35244

-

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

© Microsoft Corporation. All rights reserved.