TAB: Your Text Indentation Guru
Tired of wrestling with spaces to align your Commodore 64 text output? Want to effortlessly create beautiful columns and tables? Meet TAB
, your text indentation guru! This powerful function lets you precisely position your printed text on the screen, making formatting a breeze. Think of it as your virtual tab key for the C64!
Syntax
PRINT TAB(<column>) [;<expression>][, <expression>...]
Where:
- <column>
: The column number (1-40) where you want to start printing the next item.
- <expression>
: Any valid BASIC expression you want to print, such as strings, numbers, or variables.
- ;
: Separates expressions and outputs them without a space between.
- ,
: Separates expressions and outputs them with a tab-sized space between (usually 10 spaces).
Applications
The TAB
command is your go-to tool for:
- Creating columns: Easily align text in neat, organized columns for tables, charts, or lists.
- Formatting output: Control the horizontal spacing of your text for a more polished look.
- Building user interfaces: Design menus and prompts with clear visual organization.
Code Examples
1. Simple Tabbing:
10 PRINT "Name"; TAB(15); "Age"
20 PRINT "----"; TAB(15); "---"
30 PRINT "Alice"; TAB(15); "25"
40 PRINT "Bob"; TAB(15); "32"
This will output:
Name Age
---- ---
Alice 25
Bob 32
2. Dynamic Tabbing:
10 INPUT "Enter a word: "; W$
20 L = LEN(W$) :rem Get the length of the word
30 PRINT W$; TAB(20-L); "*" :rem Print word, then "*" right-aligned
This will print the inputted word, followed by an asterisk in column 20:
Commodore *
TAB in the Wild: The Commodore 64 Newspaper Layout Artist
Imagine you're creating a text-based newspaper on your C64. The TAB
command would be your layout artist, helping you position headlines, articles, and images in neat columns and rows, giving your publication a professional look.
Don't let haphazard formatting ruin your C64 creations! With TAB
, you can take control of your text's position on the screen, creating visually appealing and organized output. It's a simple yet powerful tool that can elevate your programming skills and make your Commodore 64 projects shine. So embrace the magic of TAB
and let your text find its perfect place on the screen!
Key Points to Remember:
TAB
is only effective withinPRINT
statements.- If the specified column is before the current cursor position,
TAB
will move to the next line and then to the specified column. - You can combine
TAB
with other formatting functions likeSPC
(for adding spaces) andPOS
(for getting the current cursor position) to create more complex layouts.