9 Output Operations
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:
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.
Image Symbol | Symbol Replication | Purpose | Comments |
---|---|---|---|
X | Yes | Blank | Can go anywhere |
" " | Text | Can go anywhere | |
D | Yes | Digit | Fill = blanks |
Z | Yes | Digit | Fill = zeros |
* | Yes | Digit | Fill = asterisks |
S | Sign | "+" or "-" | |
M | Sign | "." or "-" | |
. | Radix | Output "." | |
C | Comma | Conditional number separator | |
R | Radix | Output "," | |
P | Decimal Point | Conditional number separator | |
A | Yes | Characters | Strings |
( ) | Yes | Replicate | For specifiers, not symbols |
# | Carriage control | Suppress CRLF | |
+ | Carriage control | Suppress LF | |
- | Carriage control | Suppress CR | |
K | Compact | Strings or numerics | |
, | Delimiter | ||
/ | Yes | Delimiter | Output CRLF |
@ | Delimiter | Output FF |
"." indicates a blank space.
10 IMAGE "*****",4X"RESTART"4X,"*****" 20 PRINT USING 10 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:
70 PRINT USING "4A";"RESTART" RESTIf the item is shorter, the rest of the field is filled with blanks.
80 PRINT USING "DDDDD,2X,DD";250,45 90 PRINT USING "ZZZZZ,2X,DDDDD";251,321 100 PRINT USING "*****,2X,ZZZZZ,2X,DDDDD";99,88,77 250 45 00251 321 ***99 00088 77Only 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,456Note 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.
120 PRINT USING "DDD.DD,2X,**Z.DDD,2X,ZZZRDD";123.4,56.789,98,7 130 IMAGE DDZ.DDD,4X,ZZZ.DD 140 PRINT USING 130;.111,22.33 123.40 *56.789 098,00 7.00 0.111 022.33
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
Here are some examples:
10 N=12345.67 20 PRINT USING "DDDDD.DD";N 30 PRINT USING "DDCDDD.DD";N 40 PRINT USING "2DC3D.2D";N 50 PRINT USING "2D3DR2D";N 60 PRINT USING "ZZZCZZZ.2D";N 70 PRINT USING "6Z.2D";N 12345.67 12,345.67 12,345.67 12345,67 012,345.67 012345.67
200 IMAGE "("DDD.DD")" 210 PRINT USING 200;1.11,22.22 (1,11) (22.22) 10 IMAGE "$"DCDDDCDDD.DD 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 $.12 $12.34 $1,234.56 $123,456.78 $1,234,567.89 $$$$$$$$$$$$$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):
IMAGE | Output -17 | Output +17 |
---|---|---|
M4D | ..-17 | ...17 |
M4Z | -0017 | .0017 |
M4* | -**17 | .**17 |
S4D | ..-17 | ..Â+17 |
'T'4D | .T-17 | ..T17 |
'T'M4D | ..T-17 | ..T.17 |
DMDD | .-17 | ..17 |
DDMD | .1-7 | .1.7 |
DDDDS | ..17- | .17+ |
X, S, M or text embedded in a numeric stops the floating field.
200 IMAGE DDDDDD.DD 210 IMAGE 2DD3D.2D 220 IMAGE 6D.2DPlacing 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 5In 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) 20 IMAGE DD.D,6(DDD.DD) 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.
80 IMAGE K,2X,K,K,K 90 PRINT USING 80;"ABC",123,"DEF",456 ABC 123DEF456
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. 20 DISP "Cr/H Cl/S",SPA(25);"ASCII CHARACTER SET",LIN(1) 30 FOR Char=32 TO 127 40 DISP USING 60;CHR$(Char),Char 50 NEXT Char 60 IMAGE #,AX,"(",3D,")",3X 70 ENDThe 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. 20 DISP " ",SPA(25);"LINE DRAWING CHARACTER SET",LIN(1) 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 ENDNOTE: The actual line drawing character set displayed depends on the type of workstation you are using.
70 PRINT USING "DDD.DD";25.11,99,9 25.11 99.00 9.00
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 12.3$$$$$$$$ 12.3-1.2$$$$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 12.3$$$$