statement/PRINT statement/PRINT
NAME
PRINT USING -- Formats and writes data to the screen, file or device
ABBREVIATION
?us <shift>I
SYNOPSIS
PRINT[<file>,]USING <formatlist>;<printlist>
FUNCTION
These statements let you define the format of string and numeric items
you want to print to the screen, printer, or another device. Put the
format you want in quotes. This is the format list (<formatlist>). Then
add a semicolon (;) and a list of what you want printed in the format
for the print list (<printlist>). The list can be variables or the
actual values you want printed.
+---------------------------+---------+--------+
! Character ! Numeric ! String !
+---------------------------+---------+--------+
! Hash Sign (#) ! X ! X !
! Plus (+) ! X ! - !
! Minus (-) ! X ! - !
! Decimal Point (.) ! X ! - !
! Comma (,) ! X ! - !
! Dollar Sign ($) ! X ! - !
! Four Carets (^^^^) ! X ! - !
! Equal Sign (=) ! - ! X !
! Greather Than Sign (>) ! - ! X !
+---------------------------+---------+--------+
The hash sign (#) reserves room for a single character in the output
field. If the data item contains more characters than you have # in your
format field, PRINT USING prints nothing. For a numeric item, the entire
field is filled with asterisks (*). No numbers are printed.
For a STRING item, the string data is truncated at the bounds of the
field. Only as many characters are printed as there are hash signs (#)
in the format item. Truncation occurs on the right.
The plus (+) and minus (-) signs can be used in either the first or last
position of a format field but not both. The plus sign is printed if
the number is positive. The minus sign is printed if the number is
negative.
If you use minus sign and the number is positive, a blank is printed in
the character position indicated by the minus sign.
If you don't use either a plus or minus sign in your format field for a
numeric data item, a minus sign is printed before the first digit or
dollar symbol if the number is negative and no sign is printed if the
number is positive. This means that you can print one character more if
the number is positive. If there are too many digits to fit into the
field specified by the # and + or - signs, then an overflow occurs and
the field is filled with asterisks (*).
A decimal point (.) symbol designates the position of the decimal point
in the number. You can only have one decimal point in any format field.
If you don't specify a decimal point in your format field, the value is
rounded to the nearest integer and printed without any decimal places.
When you specify a decimal point, the number of digits preceding the
decimal point (including the minus sign, if the value is negative) must
not exceed the number of # before the decimal point. If there are too
many digits an overflow occurs and the field is filled with asterisks
(*).
A comma (,) lets you place commas in numeric fields. The position of the
comma in the format list indicates where the comma appears in a printed
number. Only commas within a number are printed. Unused commas to the
left of the first digit appear as the filler character. At least one #
must precede the first comma in a field.
If you specify commas in a field and the number is negative, then a
minus sign is printed as the first character even if the character
position is specified as a comma.
A dollar sign ($) symbol shows that a dollar sign will be printed in the
number. If you want the dollar sign to float (always be placed before
the number), you must specify at least one # before the dollar sign. If
you specify a dollar sign without a leading #, the dollar sign is
printed in the position shown in the format field.
If you specify commas and/or a plus or minus sign in a format field with
a dollar sign, your program prints a comma or sign before the dollar
sign.
The four up arrows or carets (^^^^) symbol is used to specify that the
number is to be printed in E+ format. You must use # in addition to the
^^^^ to specify the field width. The ^^^^ must appear after the # in the
format field.
You must specify four carets (^^^^) when you want to print a number in
E-format (scientific notation). If you specify more than one but fewer
than four carets, you get a syntax error. If you specify more than four
carets only the first four are used. The fifth caret (and subsequent
carets) are interpreted literally as no text symbols.
An equal sign (=) is used to centre a string in the field. You specify
the field width by the number of characters (# and =) in the format
field. If the string contains fewer characters than the field width, the
string is centered in the field. The right-most characters are truncated
and the string fills the entire field.
A greater than sign (>) is used to right justify a string in a field.
You specify the field width by the number of characters (# and =) in the
format field. If the string contains fewer characters than the field
width, the string is right justified in the field. If the string
contains more characters than can be fit into the field, the right-most
characters are truncated and the string fills the entire field.
INPUTS
<file> - logical number of target file/device
<formatlist> - printlist is formatted by using these format instructions
<printlist> - items to be printed
RESULT
Given printlist is formatted and displayed on the screen or written into
a file or device.
EXAMPLES
5 X=32:Y=100.23:A$="CAT"
10 PRINT USING "$##.##";13.25,X,Y
20 PRINT USING "###>#";"CBM",A$
When you RUN this, line 10 prints out:
$13.25$32.00$*****
PRINT USING prints ***** instead of Y value because Y has 5 digits,
which does not conform to format list.
Line 20 prints this:
CBM CAT
PRINT USING leaves three spaces before printing "CBM" as defined in
format list.
10 PRINT USING "####";X
For these values for X, this format displays:
A = 12.34 12
A = 567.89 568
A = 123456 ****
10 PRINT USING "##.#+";-.01
Result:
0.01-
Leading zero added.
10 PRINT USING "##.#-";1
Result:
1.0
Trailing zero added.
10 PRINT USING "####";-100.5
Result:
-101
Rounded to no decimal places.
10 PRINT USING "####";-1000
Result:
****
Overflow because four digits and minus sign cannot fit in field.
10 PRINT USING "###.";10
Result:
10.
Decimal point added.
10 PRINT USING "#$##";1
Result:
$1
Leading $ sign.
NOTES
None
BUGS
None
SEE ALSO
CHAR
INPUT
PRINT
PRINT#