LPRINT CHR$(9) Converts TAB to Spaces; "LPT1: BIN" Workaround (20526)



The information in this article applies to:

  • Microsoft QuickBASIC 1.0
  • Microsoft QuickBASIC 1.0a
  • Microsoft QuickBASIC 1.0b
  • Microsoft BASIC Compiler
  • 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 Q20526

SUMMARY

Question:

In Macintosh BASIC (also in CP/M and MS-DOS BASIC), a horizontal tab, or CHR$(9), is converted into eight spaces when the LPRINT statement is executed. Why does this happen? Is there any way to keep CHR$(9) from being converted into spaces?

Response:

This information applies to the following products:

  1. Microsoft QuickBASIC Versions 1.00, 1.00a, 1.00b for Apple Macintosh
  2. Microsoft BASIC Compiler Version 1.00 for Apple Macintosh
  3. Microsoft BASIC Interpreter Versions 1.x, 2.x, and 3.00 for Apple Macintosh
The LPRINT statement in BASIC converts a tab (an ASCII 9) into spaces to provide a generic, machine-independent behavior of tabs on a variety of printers.

To suppress the conversion of CHR$(9) to spaces, you can output with PRINT#n to the device "LPT1:BIN", which you OPEN as #n. "LPT1:BIN" works the same as "LPT1:DIRECT", except that the horizontal tab, CHR$(9), is not converted to spaces. "BIN" stands for "binary dump," where bytes are dumped without any translation.

"LPT1:BIN" is not supported in BASIC Interpreter Version 2.00 or BASIC Compiler Version 1.00. "LPT1:BIN" is supported in QuickBASIC Version 1.00 (both interpreter and compiler) and in BASIC Interpreter Versions 1.00, 1.01, 2.10, and 3.00.

LPRINT, "LPT1:DIRECT", and "LPT1:BIN" are supported on directly connected printers only. They are not supported for AppleTalk devices such as AppleTalk ImageWriters and LaserWriters.

The following is an example of setting your own tab stops on the Apple ImageWriter using control codes obtained from the Apple ImageWriter printer manual:
OPEN "LPT1:BIN" FOR OUTPUT AS #1
PRINT #1, "12345678901234567890"    'Provides handy tab counter.
' See Pages 57-59 of the ImageWriter printer manual for control codes:
PRINT #1, CHR$(27); "(004,009,023.";   'Sets tabs at columns 4, 9, 23.
PRINT #1, CHR$(9); "x"; CHR$(9); "y"; CHR$(9); "z"   'Uses tabs.
PRINT #1, CHR$(27); CHR$(48);     ' Clears all tabs set above.
PRINT #1, CHR$(9); "x"; CHR$(9); "y"; CHR$(9); "z"   'Tabs are clear.
CLOSE #1
				
Note that the device "LPT1:BIN" is not supported in BASIC Interpreter Version 2.00 or BASIC Compiler 1.00. To work around the tab translation to spaces in these versions, you may use BASIC's TAB function with LPRINT, instead of CHR$(9), as in the following example:
LPRINT TAB(12);"X";TAB(24);"Y"    ' This successfully performs a tab.
				

Modification Type:MinorLast Reviewed:8/16/2005
Keywords:KB20526