in BASIC ROM:
|List of all BASIC keywords|
Type: Function General Programming-Syntax: TAB(<Numeric>)
With the output function TAB the cursor position is set to logical screen column for use in BASIC output commands like PRINT. To use of more spaces at one time, it is better to use the BASIC output function SPC especially in cases the output device is different from the screen like a printer a floppy or when the BASIC-command PRINT# is used.
This function is typically used to form some kind of vertically aligned table output even the values are of different size. As an example this table of power-of-2 values from 0 to 10 (according to bit values):
10 FOR I=0 TO 10 20 PRINT 2↑I;TAB(10);I 30 NEXT I RUN 1 0 2 1 4 2 8 3 16 4 32 5 64 6 128 7 256 8 512 9 1024 10 READY.
The tabulator function is nearly the same as the comma separator for PRINT. Just replace line 20 with
PRINT 2↑I, I to get the same output as previously shown. The difference lays in how the overflow of the tabulator position is handled, which is caused by a too large output right before. TAB does nothing if the position is already beyond the desired one and simply continues on the current printing position. In contrast comma advances to the next 10th column position. However, in both cases the output gets corrupted.
Valid numbers reaches from 0 to 255 otherwise the BASIC error ?ILLEGAL QUANTITYERROR occurs. In case of a non-numerical argument the BASIC error ?TYPE MISMATCH ERROR appears. The BASIC error ?SYNTAX ERROR is shown if the argument is missing.
With the screen as output the tabulating action works by means of cursor movement to the right (the appropriate control character is taken). This changes if the output is targeted to other devices like printers or floppy files where the space character (PETSCII character code 32) is used. Similar to SPC, but the exact same behavior is only given if the screen cursor's column position is 0 even though the printing does not go to the screen. The reason for this is that TAB always takes the cursor position into account (see POS() function) regardless of the output target.
10 PRINT "TAB:" TAB(10) "6 CHARS TO COLUMN 10" TAB(54) "21 TO COLUMN 54" 20 L$="0123456789": PRINT L$;L$;L$;L$ : REM RULER
shows following output (line break a column 40)
TAB: 6 CHARS TO COLUMN 10 21 TO COLUMN 54 0123456789012345678901234567890123456789
... shows a simple tabulating mechanism.
Comparison TAB and Comma
For I=8 the value needs more then 10 characters to print and flows beyond column 10.
10 FOR I=0 TO 10 20 PRINT 10↑I, I 30 NEXT I
Even with I=7 the cursor position 10 is reached and the comma forces a positioning to tabulator position 20.
Overwriting with spaces
OPEN 1,3: CMD 1 PRINT TAB(10)
overwrites the screen content with spaces to reach the 11th column.
Special syntax cases
10 PRINT "THE LINE ..." TAB(0) 20 PRINT "CONTINUES!"
Special handling in case TAB on the end of a PRINT - behavior is the same like with a semicolon (;), which suppresses the line change.
Writes a data block with a size of 258 characters to a device behind logic channel 1 (e.g. a floppy file). By the way, the plus sign (+) is regarded as a simple separator character (not as a string operator) equivalent to a semicolon which suppresses the implicit line change.
In contrast to the previous example the plus sign (+) denotes a string operator (force by the context, the string "X") and the following expression evaluation does not expect a TAB output function leading to a break with BASIC error message ?SYNTAX ERROR.
- BASIC-ROM $AAFA: handling of TAB( uses the screen cursor column position anyway.