9 Output Operations

Formatted Output

The PRINT USING and IMAGE statements provide complete control output format by referencing a list of specifiers called an image string. The image string can be listed in an IMAGE statement and then referenced by stating the IMAGE statement line id in a PRINT USING statement:

PRINT USING line id [;print-using list]

IMAGE "format string"

Or, the image string can be contained in a string expression which is stated in place of the line id in PRINT USING:

PRINT USING string expression [;print-using list]

The string expression must be a valid image string at the time of execution.

The image string is a list of output specifiers, each separated by a delimiter. Each specifier creates a part of the output format, such as numeric and string fields, blanks, and carriage control. Each numeric or string field specifier corresponds to an equivalent item in the print-using list, and indicates how that item is to be output. The image specifiers and delimiters to be described are summarized in the next table.

An IMAGE statement must be used when literals are to be included in an image string. For example, either of these sequences is allowed:

300   IMAGE 30X,"Title"
310   PRINT USING 300
350   PRINT USING "30X,5A";"Title"
but this sequence is not:

400   PRINT USING"30X","Title""
The print-using list can contain one or more of the following:

The items are separated by either commas or semicolons. Unlike PRINT or DISP, the delimiter used has no effect on the printout. The output is totally controlled by the image string.

PRINT USING output is directed to the standard printer, the device specified by PRINTER IS. To ensure that formatted output will be directed to the display, use the DISP USING keyword in place of PRINT USING.

Summary of Image Symbols
Image Symbol Symbol Replication Purpose Comments
XYesBlankCan go anywhere
" " TextCan go anywhere
DYesDigitFill = blanks
ZYesDigitFill = zeros
*YesDigitFill = asterisks
S Sign"+" or "-"
M Sign"." or "-"
. RadixOutput "."
C CommaConditional number separator
R RadixOutput ","
P Decimal PointConditional number separator
( )YesReplicateFor specifiers, not symbols
# Carriage controlSuppress CRLF
+ Carriage controlSuppress LF
- Carriage controlSuppress CR
K CompactStrings or numerics
, Delimiter 
/YesDelimiterOutput CRLF
@ DelimiterOutput FF

"." indicates a blank space.


Three delimiters are used to separate field specs:

A comma is used only to separate two specifiers.
A slash causes output of a CRLF. When using display output fields (CURSOR), use the / to advance to the next output field. A slash can also be used to separate two specifiers.
The @ sign outputs a top-of-form (FF) signal, starting a new page of output. It can also be used to separate two specifiers.
/ and @ can also be used as specifiers by themselves; that is, they can be separated from other specs by a comma. Only the / can be directly replicated, however, as explained later.

Blank Spaces

A blank space is specified with X; nX specifies n blanks. Any X spec can be embedded within any other field spec.

String Specifications

Text can be specified in two ways:

" "
A literal spec is text enclosed in quotes. This spec may be embedded within any other field spec.
The character A is used to specify a single string character. nA specifies n characters. The length of the string spec is determined by the number of As that are specified between delimiters; this corresponds to one item in the print using list.
For example:

10   IMAGE "*****",4X"RESTART"4X,"*****"

30   Res$="RESTART"
40   IMAGE "*****"4X7A4X"*****"
50   PRINT USING 40;Res$

60   PRINT USING "5A4X7A4X5A";"*****RESTART*****"
Each of the sequences causes the same output:

*****    RESTART    *****
If the string item in the print using list is longer than the number of characters specified, the string is truncated. For example:


If the item is shorter, the rest of the field is filled with blanks.

Display Enhancements and Alternate Character Sets

As shown earlier in the manual, use of display enhancements (inverse video, etc.) and alternate character strings adds unseen characters, or control bytes, to the apparent string length. For example, this statement A$="ABCDE" actually assigns seven characters to A$, the five visible underlined characters and one control byte at each end of the string. Although these control bytes must be taken into account during string operations (dimensions, substrings, string functions, etc.), they need not be considered with IMAGE/PRINT USING operations. So the statement PRINT USING "5A"; "ABCDE" will output the entire enhanced string.

Numeric Specifications

Numeric specs can be made up of digit symbols, sign symbols, radix symbols, separator symbols and an exponent symbol. All these symbols are discussed on the following pages.

Digit Symbols

Specifies a digit position. nD specifies n digit positions. Leading zeros are replaced with a blank space as a fill character.
Specifies a digit position; nZ specifies n digit positions. Leading zeros are used as a fill character.
Specifies a digit position; n* specifies n digit positions. Leading zeros are replaced with * as a fill character.
For example:

80   PRINT USING "DDDDD,2X,DD";250,45
100  PRINT USING "*****,2X,ZZZZZ,2X,DDDDD";99,88,77

  250    45
00251      321
***99    00088     77
Only the symbol D is allowed to the right of any radix symbol (see page 285 ). Any digit symbol can be used to specify the integer portion of any number, but they cannot be mixed. (For example, if D is used they must all be D.) Thus, the following example shows an invalid image and would cause an IMPROPER PRINT USING STATEMENT message:

   110   PRINT USING "DDDZZ,2X,ZDZ";123,456
Note that there is one exception to this rule. The exception is that the digit symbol specifying the one's place can be a Z regardless of the other symbols.

Radix Symbols

A radix symbol separates the integer part of a number from the fractional part. In the United States, this is customarily the decimal point, as in 34.7. In Europe, this is frequently the comma, as in 34,7. Only one radix symbol can appear in a numeric specifier.

Specifies a decimal point in that position.
Specifies a comma in that position.
Here are some examples:

120   PRINT USING "DDD.DD,2X,**Z.DDD,2X,ZZZRDD";123.4,56.789,98,7
140   PRINT USING 130;.111,22.33

123.40  *56.789  098,00  7.00
  0.111    022.33

Sign Symbols

Two sign symbols control the output of the sign characters + and -. Only one sign symbol can appear in each numeric spec.

Specifies output of a + sign if the number is positive, - if the number is negative.
Specifies output of a - sign if it is negative, a blank if it is positive.
If the sign symbol appears before all digit symbols in a numeric spec, it floats to the left of the leftmost significant digit.

When no sign symbol is specified, any - sign occupies a digit position.

Here is an example:

150   PRINT USING "MDD.DD,2X,DDSZ,DD";-34.5,-67

-34.50   -67

Digit Separator Symbols

Digit separators are used to break large numbers into groups of digits (generally three digits per group) for greater readability. In the United States, the comma is customarily used; in Europe, the period is commonly used.

Specifies a comma as a separator in the specified position.
Specifies a period as a separator in the specified position.
The digit separator symbol is output only if a digit in that item has already been output; the separator must appear between two digits. When leading zeros are generated by the Z symbol, they are considered digits and will contain any separators.

Here are some examples:

10   N=12345.67
70   PRINT USING "6Z.2D";N


Floating Specifiers

The sign specs, S and M, or text in quotes that precede all digit specifiers in a numeric spec will "float" past blanks to the leftmost digit of the number or to the radix indicator. Here are some examples:

200   IMAGE "("DDD.DD")"
210   PRINT USING 200;1.11,22.22

(1,11) (22.22)

20   FOR I=1 TO 6
30     READ Amt
40     PRINT USING 10;Amt
50   NEXT I
60   DATA .12,12.34,1234.56,123456.78,1234567.89,12345678.90

The field of dollar signs indicates that the last item in the print-using list overflowed the image string.

Sign symbols and text that are embedded between digit symbols do not float. Here are some examples of floating and non-floating specifiers ("." indicates a blank space):

Summary of Image Symbols
IMAGE Output -17 Output +17

X, S, M or text embedded in a numeric stops the floating field.

Symbol Replication

Many of the symbols used to make up image specifiers can be replicated (repeated) by placing an integer (from 1 through 32767) in front of the symbol. For instance, the following images all specify the same image string:

210   IMAGE 2DD3D.2D
220   IMAGE 6D.2D
Placing an integer before a symbol works exactly like having multiple adjacent characters. The X, D, Z, $\ast$, A, and / symbols can be replicated directly. For example:

230   PRINT USING "5(DX)";1,2,3,4,5

1 2 3 4 5
In addition to symbol replication, an entire specifier or group of specifiers can be replicated by enclosing it in parentheses and placing an integer before the parentheses. For example:

10   IMAGE 3(K)
30   IMAGE D.D,2(DDD.DD),3(D.DDD)
40   IMAGE D,4(4X,DD.DD,"LABEL2",2X,DD)
50   IMAGE 4Z.D,4(2X,4*Z.D,(2X,D))
In this manner, both K and @ can be repeated:

70   IMAGE 4(K),2(@)
Up to four levels of nested parentheses can be used for replication.

Compacted Specifier

A single symbol, K, is used to define an entire field for either numeric or string output. If the corresponding print-using item is a string, the entire string is output. If it is a numeric, it is output in standard form. K outputs no leading or trailing blanks in numeric fields. For example:

80   IMAGE K,2X,K,K,K
90   PRINT USING 80;"ABC",123,"DEF",456

ABC   123DEF456

Carriage Control

A CRLF is normally output when the print-using list is exhausted. This can be altered by using a carriage control symbol as the first item in an image string; a comma must separate it from the next item.

Suppresses both the carriage return and linefeed.
Suppresses the linefeed.
Suppresses the carriage return.
For example:

30   IMAGE #,4(A,2X)
40   IMAGE K
50   PRINT USING 30;"A","B","C","D"
60   PRINT USING 40;"***"

A  B  C  D  ***
Notice that PRINT USING "+" is equivalent to PRINT LIN(0); and PRINT USING "-" is equivalent to PRINT LIN(-1).

Here is a short program which uses carriage control and symbol replication in a DISP USING image to print a table of ASCII characters and decimal values.

10   !     Display ASCII character set.
30   FOR Char=32 TO 127
40     DISP USING 60;CHR$(Char),Char
50   NEXT Char
60   IMAGE #,AX,"(",3D,")",3X
70   END
The program above creates the following output:

                         ASCII CHARACTER SET

  ( 32)   ! ( 33)   " ( 34)   # ( 35)   $ ( 36)   % ( 37)   & ( 38)   ' ( 39)
( ( 40)   ) ( 41)   * ( 42)   + ( 43)   , ( 44)   - ( 45)   . ( 46)   / ( 47)
0 ( 48)   1 ( 49)   2 ( 50)   3 ( 51)   4 ( 52)   5 ( 53)   6 ( 54)   7 ( 55)
8 ( 56)   9 ( 57)   : ( 58)   ; ( 59)   < ( 60)   = ( 61)   > ( 62)   ? ( 63)
@ ( 64)   A ( 65)   B ( 66)   C ( 67)   D ( 68)   E ( 69)   F ( 70)   G ( 71)
H ( 72)   I ( 73)   J ( 74)   K ( 75)   L ( 76)   M ( 77)   N ( 78)   O ( 79)
P ( 80)   Q ( 81)   R ( 82)   S ( 83)   T ( 84)   U ( 85)   V ( 86)   W ( 87)
X ( 88)   Y ( 89)   Z ( 90)   [ ( 91)   \\ ( 92)   ] ( 93)   ^ ( 94)   _ ( 95)
  ( 96)   a ( 97)   b ( 98)   c ( 99)   d (100)   e (101)   f (102)   g (103)
h (104)   i (105)   j (106)   k (107)   l (108)   m (109)   n (110)   o (111)
p (112)   q (113)   r (114)   s (115)   t (116)   u (117)   v (118)   w (119)
x (120)   y (121)   z (122)   { (123)   | (124)   } (125)   ~ (126)   (127)
A DISP statement is used to output the table header, since display control characters cannot be output within a DISP USING statement.

A similar program is used to display a table of line drawing characters. In line 40, a non-ASCII character (decimal value 147) is concatenated with each character in the series to set the line drawing mode. Lines 50 through 80 insert a CRLF after each nine data sets displayed.

10   !     Display LINE DRAWING character set.
30   FOR Char=161 TO 246
40     DISP USING 100;CHR$(147)CHR$(Char),Char
50     I=I+1
60     IF I

9 THEN 90
70     DISP
80     I=0
90   NEXT Char
100  IMAGE #,AX,"(",3D,")",2X
110  END
NOTE: The actual line drawing character set displayed depends on the type of workstation you are using.

Reusing the Image String

An image string is reused from the beginning if it is exhausted before the print-using list. A CRLF is not normally output until the list is exhausted. For example:

70   PRINT USING "DDD.DD";25.11,99,9

25.11 99.00  9.00

Field Overflow

If a numeric item requires more digits than the field spec provides, an overflow condition occurs. When this happens, the item which causes the overflow is replaced with a field of dollar signs. Then the rest of the print-using list is output. For example:

105  IMAGE 3(DD.D)
110  PRINT USING 105;111.11,2,33.3
120  PRINT USING 105,12.3,123,1234.56
130  PRINT USING 105;12.3,-1.2,-12.3

$$$$ 2.033.3
Remember that a minus sign not explicitly specified with S or M requires a digit position. For instance:

140   PRINT USING "2(DD.D)";12.3,-45.6


Eloquence Language Manual - 19 DEC 2002