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:
- Microsoft QuickBASIC Versions 1.00, 1.00a, 1.00b for Apple
Macintosh
- Microsoft BASIC Compiler Version 1.00 for Apple Macintosh
- 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.