Microsoft KB Archive/39578

= CHR$(0) PRINTs As Space to Screen; LPRINTs Nothing to Printer =

Article ID: 39578

Article Last Modified on 11/21/2006

-

APPLIES TO


 * 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

-



This article was previously published under Q39578



SUMMARY
CHR$(0) (a null byte) is a non-printable character in MS-DOS. However, the PRINT and PRINT USING statements in Basic print this character as a space.

Sending CHR$(0) to the following MS-DOS logical device names will print nothing:

&quot;CONS:&quot;

&quot;LPTn:&quot;

&quot;COMn:&quot;

&quot;SCRN:&quot;

Likewise, printing CHR$(0) with the LPRINT or LPRINT USING statements sends nothing.

Fixed-length strings are initialized to null bytes. Printing these fixed-length strings to the screen and to the printer will give different column alignment. This difference can be circumvented by using the STRING$ function to initialize the fixed length string with spaces.



MORE INFORMATION
This information applies to Microsoft QuickBasic Versions 4.00, 4.00b, and 4.50, and to Microsoft Basic Compiler Versions 6.00 and 6.00b for MS-DOS and MS OS/2.

The following is a code example: 'The following piece of code will print an uninitialized fixed-length 'string to the screen and printer using the PRINT and LPRINT 'statements. Unless the STRING$ function is used to fill the 'fixed-length string with spaces, the hard copy and screen will show 'different column alignment. TYPE aType Field1 AS STRING * 32   ' a fixed length string END TYPE DIM aVariable AS aType CLS ' Comment out the following line to cause different column alignment ' between LPRINT and PRINT; otherwise columns will line up the same: aVariable.Field1 = STRING$(32, &quot; &quot;)

' Use LPRINT: FOR i = 1 TO 10: LPRINT : NEXT i LPRINT &quot;printing aVariable.Field1 to printer with 'xxxx' following&quot; LPRINT &quot;1234567890123456789012345678901234567890&quot; LPRINT aVariable.Field1; &quot;xxxx&quot; LPRINT &quot;printing aVariable.Field1 with LPRINT USING '\    \xxxx'&quot; LPRINT USING &quot;\    \xxxx&quot;; aVariable.Field1 FOR i = 1 TO 10: LPRINT : NEXT i

' Use PRINT: PRINT &quot;printing aVariable.Field1 to screen with 'xxxx' following&quot; PRINT &quot;1234567890123456789012345678901234567890&quot; PRINT aVariable.Field1; &quot;xxxx&quot; PRINT &quot;printing aVariable.Field1 with PRINT USING '\    \xxxx'&quot; PRINT USING &quot;\    \xxxx&quot;; aVariable.Field1

Additional query words: QuickBas BasicCom

Keywords: KB39578

-

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

© Microsoft Corporation. All rights reserved.