| Previous | Contents | Index |
The USING option is used to format text. The print mask indicates the format for the data in the print list.
USING print_mask
|
The print_mask consists of fields or directives and text. The text can precede or follow a field or directive. The print mask tells how to print the expressions in the print list.
| Example 7-14 USING option in PRINT statement - print_mask |
|---|
let a$ = "#.## ##.##" //<---- two fields
print using "amount = #.##": 1.9
print using a$: 1.93, -1.93
end
amount = 1.90
1.93 -1.93
|
Expressions in the print list with the USING option are separated by commas. A trailing semicolon is allowed. The expressions are printed according to the format. However, a trailing semicolon causes SheerPower to leave the cursor at the end of the print line.
| Example 7-15 PRINT USING |
|---|
print using "###.## ###.##": 22.88, 45;
print " and others."
end
22.88 45.00 and others.
|
Fields are made up of format characters. The format characters tell SheerPower how to print the expressions in the print list.
The # is used to indicate a character position---a place in the format where a character can occur. For example:
| Example 7-16 String format characters in PRINT USING |
|---|
print using '#### ##': 'Test', 'Hi'
end
Test Hi
|
In the above example, there are two fields. When the first string is printed, the word "Test" occupies all four character positions. When the second expression is printed (Hi), only two character positions are used.
If the string expression being printed is smaller than the field, the expression will be printed centered within the field.
| Example 7-17 String format characters in PRINT USING |
|---|
print using '#### ####': 'Test', 'Hi'
print '123456789'
end
Test Hi
123456789
|
If the string expression is longer than the field, SheerPower generates an exception.
The # can also be used to specify digits. Each # represents one numeric digit position.
| Example 7-18 Numeric format characters in PRINT USING |
|---|
print using "##": 19
end
19
|
If more positions than the numeric expression contains are indicated, the expression will be right-justified and padded with spaces.
| Example 7-19 Numeric format characters in PRINT USING |
|---|
print '1st 2nd 3rd'
print using "### ### ###": 193, 19, 1
end
1st 2nd 3rd
193 19 1
|
SheerPower prints a minus sign in front of negative numbers. SheerPower does not print a sign in front of positive numbers.
| Example 7-20 Numeric format characters in PRINT USING - negative and positive numbers |
|---|
print '1st 2nd 3rd'
print using "### ### ###": 193, 19, -1
end
1st 2nd 3rd
193 19 -1
|
If more positions to the left of the decimal point than the expression contains are indicated, the expression will be printed with leading spaces.
| Example 7-21 Numeric format characters in PRINT USING |
|---|
print using "###.##": 1.9
end
1.90
|
If more positions to the right of the decimal point than the expression contains are indicated, the expression will be printed with trailing zeros.
| Example 7-22 Numeric format characters in PRINT USING |
|---|
print '--1-- --2--'
print using "##.## ##.##": 1.3, 1.25
end
--1-- --2--
1.30 1.25
|
The less than sign left-justifies text within a field. The less than sign must appear at the beginning of a field. The less than sign counts as a character position. In this example, justification occurs only in the second field.
| Example 7-23 < character in PRINT USING |
|---|
print using "#### <###": 'Test', 'Hi'
print '123456789'
end
Test Hi
123456789
|
In the above example, there are two fields. When the first string is printed, the word "Test" occupies all four character positions. The less than sign (<) causes SheerPower to left-justify the second expression.
The greater than sign is used to right-justify text within a field. The greater than sign must appear at the beginning of a field. The greater than sign counts as a character position.
| Example 7-24 > character in PRINT USING |
|---|
print using "#### >###": 'Test', 'Hi'
print '123456789'
end
Test Hi
123456789
|
In the above example, there are two fields. The greater than sign (>) causes SheerPower to right-justify the second expression.
The @ indicates one character position with no translation.
| Example 7-25 @ character in PRINT USING |
|---|
print using '####': 0001
print using '@@@@': 0001
end
1
0001
|
You can include a decimal point in a number by putting a period or decimal point in the format.
| Example 7-26 . character in PRINT USING |
|---|
print using "###.##": 19.3
end
19.30
|
Include commas in your numbers by putting commas in the format.
| Example 7-27 , character in PRINT USING |
|---|
a$ = "##,###.##"
print using a$: 28290.06
print using a$: 8290.06
print using a$: 290.06
end
28,290.06
8,290.06
290.06
|
Commas cannot be used in exponential format.
The % character pads on the left with zeros.
| Example 7-28 % character in PRINT USING |
|---|
print '-1- -2- -3-'
print using "%%% %%% %%%": 193, 19, 1
end
-1- -2- -3-
193 019 001
|
The * character pads on the left with asterisks. This symbol can be used to set up check amounts.
| Example 7-29 * character in PRINT USING |
|---|
print using '***,***.**': 19.42
end
*****19.42
|
If the expression is smaller than the format, SheerPower will right justify the expression and pad it with asterisks.
| Example 7-30 * character in PRINT USING |
|---|
print '-1- -2- -3-'
print using "*** *** ***": 193, 19, 1
end
-1- -2- -3-
193 *19 **1
|
A plus sign causes SheerPower to print a leading plus or minus sign. SheerPower will print a plus sign in front of positive numbers and a minus sign in front of negative numbers.
The "+" sign adds a character position to the format. The character position is used for the sign of the number.
| Example 7-31 + character in PRINT USING |
|---|
print ' -1- -2- -3-'
print using "+### +### +###": 193, 19, -1
end
-1- -2- -3-
+193 +19 -1
|
The - character prints a leading or trailing minus sign for negative numbers, and a leading space for positive numbers. The "-" adds a character position to the format. The character position is used to print the minus sign or space.
| Example 7-32 - character in PRINT USING |
|---|
print ' -1- -2- -3-'
print using "-### -### -###": 193, 19, -1
end
-1- -2- -3-
193 19 -1
|
| Previous | Next | Contents | Index |