Formatted Output in QBASIC
Text Alignment
This function moves the cursor to the print
position when used in the PRINT and LPRINT statements.
Syntax: TAB (column)
Where,
Column, we have to mention the number of column
where we want to display the text.
Example:
REM Example of TAB function CLS a$ = "QBASIC" b$ = "Programming" PRINT a$; TAB(10); b$ END |
Output |
SPC
This function skips the specified number of
spaces in a PRINT and LPRINT statement.
Syntax: SPC(n)
Where,
n, number of spaces
REM Example of SPC function CLS PRINT "School"; SPC(8);
"Level"; SPC(5); "Programming" END |
Output |
This function moves the cursor to the
specified position. monitor. It accepts the row and column position while moving the
cursor.
Syntax: LOCATE [row, column]
Where,
row, column are the number of row and column which the
cursor moves.
REM Example of LOCATE function CLS LOCATE 3, 10 PRINT "School Level Programming" LOCATE 5, 17 PRINT "QBASIC" END |
Output |
PRINT "Text Alignment Example"
PRINT "---------------------"
PRINT "Using TAB Function:"
PRINT "Column 1"; TAB(10); "Column 2"; TAB(20); "Column 3"
PRINT "Value 1"; TAB(10); "Value 2"; TAB(20); "Value 3"
PRINT "Using SPC Function:"
PRINT "Item"; SPC(10); "Quantity"; SPC(10); "Price"
PRINT "-----"; SPC(10); "--------"; SPC(10); "-----"
PRINT "Apples"; SPC(10); 10; SPC(10); "$1.50"
PRINT "Bananas"; SPC(10); 5; SPC(10); "$0.75"
PRINT "Oranges"; SPC(10); 3; SPC(10); "$2.00"
Numeric Formatting
PRINT USING Statement
This
statement is used to print strings or numbers using a specified format on the
screen.
Syntax:: PRINT
USING “format string” ; expression
CLS PRINT USING “#####.##” ; 1234 PRINT USING”###.#” ; 123.275 END |
Output: 1234.00 123.2 |
Character |
Result |
# |
Digit
position |
+ |
Position
of number’s sign |
. |
Decimal
point position |
- |
Prints
trailing minus sign for negative numbers only |
** |
Fills
leading spaces with * |
$$ |
Prints
leading $ |
**$ |
Combines
** and $ |
^^^^ |
Prints
number in exponential format |
Character |
Result |
& |
Prints
entire string |
! |
Prints
only the first character |
\ \ |
Prints
first ‘n’ characters, where n is the number of blanks between slashes + 2 |
LPRINT and LPRINT USING Statements
Syntax:
LPRINT [Expression list] [, or ;]
Example: LPRINT “This line directly goes to printer”
Note: The LPRINT statement causes the PRINT
statements to be directed to the printer instead of directing to the screen
No comments:
Post a Comment