Chapter 7: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
No edit summary
m ("Numeric number" changed to "numeric variable")
 
(3 intermediate revisions by 2 users not shown)
Line 17: Line 17:
The information in the right corner of your status line allows you to keep track of the cursor’s current screen position.  The number on the left side of the colon shows the cursor’s row number (since the cursor does not scroll, this number will almost always be 24 when you are writing a program), and the number to the right of the colon shows the column number.  
The information in the right corner of your status line allows you to keep track of the cursor’s current screen position.  The number on the left side of the colon shows the cursor’s row number (since the cursor does not scroll, this number will almost always be 24 when you are writing a program), and the number to the right of the colon shows the column number.  


You have already used the PRINT statement for unformatted printing.  When an unformatted PRINT statement is executed, numeric strings which contain more than six whole number digits are printed in exponential form, and numeric strings which contain more than six decimal digits are rounded.   
You have already used the PRINT statement for unformatted printing.  When an unformatted PRINT statement is executed, numeric strings which contain more than ten whole number digits are printed in exponential form, and numeric strings which contain more than six decimal digits are rounded.   


To demonstrate this, what happens when you run this one-line program?  
To demonstrate this, what happens when you run this one-line program?  


  00010 PRINT 123456789,.123456789  
  00010 PRINT 12345678901,.123456789  
  RUN  
  RUN  


The first number (1.2345678e+008) is printed in exponential form, and the second (0.123456) is rounded to six digits.  
The first number (1.2345678901e+10) is printed in exponential form, and the second (0.123457) is rounded to six digits.  


Formatted PRINT statements allow you to choose the number of digits which will appear before exponentiation or rounding occurs.  Formatted printing is usually used in reports, where information must fit into predetermined slots. This is described later in the chapter.  
Formatted PRINT statements allow you to choose the number of digits which will appear before exponentiation or rounding occurs.  Formatted printing is usually used in reports, where information must fit into predetermined slots. This is described later in the chapter.  
Line 245: Line 245:
  00010 LET NUMBER=1121  
  00010 LET NUMBER=1121  
  00020 LET MAGNAME$=”Cycle Digest”  
  00020 LET MAGNAME$=”Cycle Digest”  
  00030 LET CIRC=74,030
  00030 LET CIRC=74030
  00040 LET SUBSCRIP=52,476
  00040 LET SUBSCRIP=52476
  00050 PRINT NUMBER;MAGNAME$;CIRC;SUBSCRIP  
  00050 PRINT NUMBER;MAGNAME$;CIRC;SUBSCRIP  


Line 375: Line 375:
C and N conversion specifications  
C and N conversion specifications  


The FORM statement provides you with several conversion specification options, but the two that you will probably use most frequently are C and N.  C stands for character, and it signals that the system is to print a character string.  N stands for numeric, and it signals that the system is to print a numeric number.  The second numeric parameter in the specification indicates the length of the field where it will print.  
The FORM statement provides you with several conversion specification options, but the two that you will probably use most frequently are C and N.  C stands for character, and it signals that the system is to print a character string.  N stands for numeric, and it signals that the system is to print a numeric variable.  The second numeric parameter in the specification indicates the length of the field where it will print.  


[[image:7.6.png]]
[[image:7.6.png]]
Line 556: Line 556:
[[Solutions#CHAPTER 7|Solution]]
[[Solutions#CHAPTER 7|Solution]]


NEXT:[[Chapter 8]]
NEXT:[[Chapter 8|FOR/NEXT and ON GOTO]]


[[BR Tutorial|Back to Index]]
[[BR Tutorial|Back to Index]]

Latest revision as of 17:11, 25 April 2020

PRINT is a multi-talented statement.  In this chapter you will use it to clear the screen, to tone the print “bell,” and to produce both unformatted and formatted output.  When you are finished you should be able to:  

  • Explain the difference between unformatted and formatted printing.
  • Describe the screen in terms of rows and columns.
  •  Use both commas (for zone printing) and semi-colons in a PRINT statement.
  •  Describe and use the BELL, NEWPAGE, and TAB options of the print statement.
  •  Produce formatted output with PRINT USING and the FORM statement.
  • Explain the uses of the C and N conversion specifications.
  •  Explain the uses of the PIC conversion specification, insertion characters & identifiers.
  • Describe and use the POS, X, and SKIP cursor position specifications.

7.1 The design of your screen

Your Business Rules! screen is divided into rows and columns.  A row is the horizontal space that one line of text takes up on the screen.  A column is the vertical space that a single character in each row takes from the top to the bottom of the screen. Business Rules! default screen allows you to see 24 horizontal rows and 80 vertical columns at a time. This default can be changed with the OPEN statement, which you'll learn about in a later section. 

The information in the right corner of your status line allows you to keep track of the cursor’s current screen position.  The number on the left side of the colon shows the cursor’s row number (since the cursor does not scroll, this number will almost always be 24 when you are writing a program), and the number to the right of the colon shows the column number.

You have already used the PRINT statement for unformatted printing.  When an unformatted PRINT statement is executed, numeric strings which contain more than ten whole number digits are printed in exponential form, and numeric strings which contain more than six decimal digits are rounded. 

To demonstrate this, what happens when you run this one-line program?

00010 PRINT 12345678901,.123456789 
RUN 

The first number (1.2345678901e+10) is printed in exponential form, and the second (0.123457) is rounded to six digits.

Formatted PRINT statements allow you to choose the number of digits which will appear before exponentiation or rounding occurs.  Formatted printing is usually used in reports, where information must fit into predetermined slots. This is described later in the chapter.

There is also another kind of printing, accomplished with PRINT FIELDS statements, which allows you to choose both the row and the column that printing will occur in.  PRINT FIELDS will be discussed in another chapter.

Quick Quiz 7.1

1. Match the following:

A. Formatted 1) Exponentiation & rounding occurs after 6 digits
B. Rows 2) Total of 24
C. Unformatted 3) Total of 80
D. Columns 4) Used mainly in reports

2. What part of the status line tells you the current column position of the cursor?
a)   The number just before the colon in the right corner of the status line.
b)   The number in the center of the status line
c)   The number just after the colon in the right corner of the status line.

3. Which type(s) of printing allow you to choose the number of digits which will be printed before exponentiation or rounding occurs?
a)   Unformatted
b)   Formatted

Answers 7.1

7.2 Sending PRINT output to the printer

So far you have only used PRINT to print information on the screen, but this statement can also be used to send information to another file or to a printer (you will learn more about printing to a file when you study the OPEN statement).

To send information to the printer, you must tell Business Rules to use the printer by specifying the Business Rules reserved file number for the printer, which is #255, in your PRINT statement. The example below will send the specified phrase to the printer rather than to the screen:

10 PRINT #255: "The peddler wore rabbit skin boots." 

Before printing to the printer, you must first open the printer using the OPEN statement. You can also use this statement to specify which printer to print to, or to use a number other than #255 for the printer. For more information on printing, see the Business Rules Wiki at [1].  The following code will send the print job to the default printer, showing a nice preview window where the user can select any other printer they want before the job is printed.  

5 OPEN #255: "name=preview:/, recl=500",display,output 

Business Rules! also has a special file number (#0) for sending information to the screen. File 0 is the Business Rules output window.  Since Business Rules! automatically prints to the screen unless it is told to do otherwise, it is not usually necessary to use this code (although you may if you wish).  The following two statements perform the same action:

00100 PRINT “The acid odor burned her throat.” 
01000 PRINT #0:”The acid odor burned her throat.” 

Quick Quiz 7.2

1. Where does Business Rules! send PRINT information when a location is not specified in the PRINT statement?
a)   To the printer.
b)   To the screen.
c)   PRINT statements are not executed unless the output location is specified.

2. Which of the following PRINT statements will send the specified string to the printer?
a)   PRINT 255: AGATE
b)   PRINT 0 CONCRETE
c)   PRINT #255: JELLO

Answers 7.2

7.3 PRINT’s BELL and NEWPAGE options

The PRINT statement has two options which cause actions other than printing.  PRINT with the BELL option sends a message to the hardware that causes it to beep, and PRINT with the NEWPAGE option causes the current screen to clear.

PRINT BELL can be useful for error-handling routines or in any situation where you want the operator to pay special attention to what’s going on.

Line 2310 in the following example shows the use of PRINT with the BELL option during an error-handling routine.  The BELL keyword should always be followed with a semi-colon, as shown: File:7.2.png

The above program branches to line 2300 (a remark statement) when the operator causes an error at line 200.  The next line causes the system bell to sound.  It is followed with a printed message to the operator, and then the program branches back to the statement where the error occurred.

When a printer and the BELL option are specified in a PRINT statement (see the example), Business Rules! causes the printer to beep:

60000 PRINT #255: BELL; 

PRINT BELL can also be used as a command in Business Rules!, although its use is mostly limited to discovering what the “bell” in your computer or printer sounds like.

PRINT NEWPAGE

The second nonprint option of PRINT erases the screen.  PRINT NEWPAGE can be used at the beginning of a program or anywhere else that you wish to provide a clean screen.   It is a good practice to include PRINT NEWPAGE as the first executable statement in all of your major programs.  The following example illustrates this usage.  The NEWPAGE keyword should always be followed with a semi-colon, as shown:

When a printer and the NEWPAGE option are specified in a PRINT statement (see the example), Business Rules! causes the printer to advance to the next page:

60000 PRINT #255: NEWPAGE; 

The NEWPAGE option can also be used as a command in Business Rules!.  If you are familiar with other dialects of BASIC, then you should be very careful to remember the difference between NEWPAGE as a command and CLEAR.  NEWPAGE erases the screen without affecting memory.  CLEAR removes all programs and data from Business Rules! current memory, but it does not clean the screen.

Once you have executed a CLEAR command, there is no way to recover the program stored in current memory.  It is a good idea to frequently SAVE and REPLACE programs that you are working on for a number of reasons (such as potential hardware or power failure), but this is twice as important if you are likely to confuse the uses of CLEAR and PRINT NEWPAGE.

Quick Quiz 7.3

1. When should you use the BELL option of the PRINT command?
a)   It should be the first executable statement of the program.
b)   Any situation where the operator should pay special attention to what’s going on.
c)   Whenever the system clock says it’s twelve o’clock noon.

2. What happens when the NEWPAGE option of the PRINT command is sent to the printer?
a)   The printer advances the paper to the next page.
b)   The screen goes blank.
c)   The printer prints the word “NEWPAGE.”
d)   Both a and b.

3. What punctuation should always follow the BELL and NEWPAGE keywords when they are used in PRINT statements?
a)   A colon.
b)   A comma.
c)   A semi-colon.

Answers 7.3

7.4 Unformatted PRINT statements

All the PRINT statements that you have used so far with this tutorial have been unformatted.  The typical unformatted PRINT statement contains a line number, the PRINT keyword, and one or more data items, which can be either numeric or character expressions.  In the following example, the variable ID_NUMBER$ is the specified data item:

00100 PRINT ID_NUMBER$ 

Unformatted PRINT statements which include more than one data item may use either commas or semi-colons as separators.  When a comma is used, zoned printing occurs.

Zoned Printing

Business Rules! divides output space into five zones of 24 characters each.  On a 132-character-per-line printer, these zones occur at columns 1, 24, 48, 72, and 96. Since the typical screen is only 80 columns wide, zoned printing occurs only in three columns when you are looking at the screen: 1, 24, and 48. (Data items in the fourth and fifth zones are automatically printed only the next line.)

The first data item in a PRINT statement is printed in the first zone.  The second data item is printed in the next available zone (individual data items may take up as many zones as is necessary).  Each data item is printed in turn.  There is no limit to the number of data items which may be used in a single PRINT statement.

If all the zones in a row are used before all the data items in the statement are printed, Business Rules! continues printing in the next row.  The following statement:

00100 PRINT ID_NUMBER$, NICKNAME$, HEIGHT$, WEIGHT$ 

could produce this output on the screen:

Column 1  Column 24  Column 48
999-64-5607 WIZARD 6/0
192

The same statement, when sent to a printer which prints 132 characters per line, would print the information in a single line as follows:

Column 1 Column 24  Column 48 Column 72
999-64-5607      WIZARD          6/0              192
Overriding zoned printing

The use of semi-colons instead of commas to separate data items overrides zone printing.  Multiple data items are then printed in one long string, as shown in the following example:

00100 PRINT ID_NUMBER; NICKNAME$; HEIGHT$; WEIGHT$ 

will print this:

999-64-5607WIZARD6/092     

Quick Quiz 7.4

1.Business Rules! distinguishes between the use of commas and semi-colons in PRINT statements.  What function do these punctuation symbols perform? 
a)   Operate as data items.
b)   Determine where PRINT data will be printed (comma=screen, semi-colon=printer).
c)   Separate data items.

2. What is the maximum number of characters that a single data item may consist of?
a)   Two zones (48 characters).
b)   30
c)   There is no limit to the number of data items which may be used in a single PRINT statement.

3. What is zoned printing?
a)   A type of formatted printing.
b)   Printing from a program that was written in a different time zone.
c)   Printing of separate data items in preset spaces.

4. Which of the following statements about zoned printing is true?
a)   Use of semi-colons instead of commas (as data item separators) will override zoned printing.
b)   When PRINT statement output is directed to the screen, the statement may contain only three data items.
c)   When a data item takes up more than one zone, the next data item is printed in the next available column.

Answers 7.4

Mid-Chapter Practice:

Using your program NEWSAL (from Chapter 6), override zoned printing to list the salary increases for each employee. What else do you think could be done to make the numbers clearer? (Consider spacing and how dollar amounts are usually written).

Solution

7.5 Leading and trailing spaces

Whenever Business Rules! prints numeric data items, it adds a leading space (before) and a trailing space (after) the variable.  You should consider these spaces to be part of the printed information.  As an example, study the following statement and its output:

00010 PRINT TODAYS;WORKER_NUM;COST 
RUN
12  6  2160  

The spaces before each variable is a leading space while the space following each variable is a trailing space.

Business Rules! also adds leading and trailing spaces to data items which are zone printed:

00010 PRINT TODAYS, WORKER_NUM,COST 
RUN 
12                     6                     2160       

Columns 1, 24 and 72 (the column before each variable) are leading spaces.  

But Business Rules! does not add leading and trailing spaces to character data items.  If you are not careful to plan for this, you could end up with output strings that “run” together, as in the following example:  File:7.4.jpg   The way to correct the problem is to add desired spaces within delimiters when you specify the values of string variables.  The above example could be corrected by adding a space at the beginning and end of the PRINT statement’s “is located in” string:

00030 PRINT CUST$;” is located in “;LOCATION$ 
RUN 

H.E. Construction is located in Deerfield, IL.

Quick Quiz 7.5

Study the following set of statements and then answer the questions:

00010 LET NUMBER=1121 
00020 LET MAGNAME$=”Cycle Digest” 
00030 LET CIRC=74030 
00040 LET SUBSCRIP=52476 
00050 PRINT NUMBER;MAGNAME$;CIRC;SUBSCRIP 

1. What screen column will the first digit of the NUMBER value be printed in?
a)   Column 1.
b)   Column 2.
c)   Column 3.

2. What screen column will the first letter of the MAGNAME$ variable appear in?
a)   Column 6.
b)   Column 7.
c)   Column 24.
d)   Column 25.

3. How many blank spaces will there be between the MAGNAME$ and the CIRC values?
a)   Zero.
b)   One
c)   Two
d)   Thirteen.

Answers 7.5

7.6 Print's TAB option

Sometimes you will find that your unformatted printing requires greater flexibility than zone printing can give you.  You may want to use more than five zones in a single row, for instance.  This is when the PRINT statement’s TAB option will come in handy.  

TAB(x) allows you to specify which column the next data item should be printed at (x is the column number). 

Study the following example:

00010 PRINT WINDOWS;TAB(20);DOORS;TAB(40);STEPS 
RUN 
Column 1        Column 30    Column 50     

          16                     6                      2160

Notice that TAB is set off from the data items with semi-colons.  The use of commas would confuse Business Rules! into trying to zone print.  Also notice that the secondary keyword, TAB, is followed by a set of parentheses and the number of spaces until the next data item.  Any numeric expression can be used within these parentheses: whatever number it evaluates to is the column number at which Business Rules! will print the next data item.  Exceptions to this rule are listed below:

Exception Result
Current column position of the cursor is greater than x. The data item is printed in the next row in column x.
x is negative TAB(1) is assumed.
x is not an integer X is roudned to the nearest integer.
x is greater than the record length (the number of columns in the row). The data item is printed on the next row in column 1.

Business Rules! allows you to use a combination of commas, semi-colons and the TAB option in the same PRINT statement.  Just be sure to remember that TAB should be set off with semi-colons rather than commas.

Quick Quiz 7.6

1. What does the x in TAB(x) stand for?
a)   The number of spaces between columns.
b)   The column number of the next data item.
c)   The number of data items to be printed in the next print zone.

2. What happens when the value of x is smaller than the current column position of the cursor?
a)   The data item is printed in column 1 of the next row.
b)   The data item is printed in column x of the next row.
c)   The cursor moves x spaces and prints the data item.
d)   The data item is printed in the next zone.

3. Write a PRINT statement that achieves the following:
a)   The value of CHART (108) is printed starting in column 12.
b)   The value of PEAK (2) is printed in zone 2.
c)   The statement “this is a new page” is printed in zone 3.

Answers 7.6

Mid-Chapter Practice:

Using your program NEWSAL again, use TAB to spread out each salary amount across the screen.

Solution

7.7 Formatted Printing

When PRINT is used in conjunction with a USING option and the FORM statement, formatted printing is the result.  Formatted printing can be used to regulate the lengths of printed values and to insert characters -- such as dollar signs -- immediately before printed numbers.  It is most often used in the printing of reports.

Formatted printing is separate from unformatted printing; the two types cannot be specified in the same PRINT statement.  The formatted PRINT statement typically includes a line number, the keyword PRINT, the secondary keyword USING along with a line reference to a FORM statement and a required colon, and one or more data items:

00010 PRINT USING 20: VITAMIN_A,RIBOFLAVIN,CALCIUM,PROTEIN 

The above statement tells Business Rules! to print the specified data items using the FORM statement located at line 20.  The format statements are executed only when a PRINT USING statement specifically refers to them.  Otherwise they are ignored.    Before we discuss the FORM statement itself, it is important for you to understand some of the FORM statement’s terminology.   A field, in computer lingo basically refers to the space allotted to a piece of information, usually text.   When printed, the values of the variables in the following PRINT statement will each occupy their own field.  The length of the value (the number of characters) is not necessarily the same length as the field however--and this is an important distinction.  A field of predetermined length can be reserved for a particular value, but that value does not have to fill the field.   As an example of this concept, the FORM statement in line 60 below sets up four fields of 15 columns in length (do not be concerned if you do not follow the PRINT USING and FORM statements yet - we are mostly concerned with the printed output in this example).  In each case however, the values within the field are less than fifteen columns wide:


Field #1               Field #2               Field #3              Field #4 

Quick Quiz 7.7

1. Which option of the PRINT statement must be used for formatted printing?
a)   TAB
b)   USING
c)   FORM

2. What punctuation is required after the line-ref in the PRINT USING statement?
a)   A comma.
b)   A set of quotation marks.
c)   A colon.

3. Identify the false statement:
a)   A field is the amount of horizontal space which is allotted to a piece of information.
b)   The specifications for formatted and unformatted printing are very similar; they can even be mixed in the same PRINT statement.
c)   The PRINT USING statement contains a line-ref to the FORM statement that specifies the format of the information to be printed.

Answers

 

7.8 The FORM statement

The FORM statement consists of a list of format specifications. A specification is a letter or group of letters followed by a number and separated by commas when listed in a FORM statement.

The FORM statement must contain a line number and the FORM keyword, followed by the Cursor Position Specifications (POS) and the Print Specifications. POS gives Business Rules! details on where the cursor should appear, while the print specification gives Business Rules! details on how to execute the print. Do not be concerned if the following FORM statement illustration looks confusing.  You will have a much clearer understanding of FORM’s syntax when you are finished with this chapter.

00010 FORM POS 2,N 2,X 10,N 2,X 10,N 2 

Since conversion specifications can be used by themselves, the rest of this lesson and the next lesson will focus mainly on the N, C, and PIC conversion specifications.  The following lesson will then explain three ways to alter the cursor position with the FORM statement.

C and N conversion specifications

The FORM statement provides you with several conversion specification options, but the two that you will probably use most frequently are C and N.  C stands for character, and it signals that the system is to print a character string.  N stands for numeric, and it signals that the system is to print a numeric variable. The second numeric parameter in the specification indicates the length of the field where it will print.

In the above example, line 10 tells Business Rules! to print the specified character strings using the format specifications at line 20.  Line 20 then specifies the printing of two character strings: the first is to be placed in a field of 10 columns.  Notice that character strings are left-aligned. The printing of numeric values works much the same way, except they are right-aligned:

 

When a number is to be printed with a decimal point and one or more decimal digits, this information must be included along with the field length.  The specification is the same as above except that the field length number includes a period and the quantity of decimal digits to be printed.

The above FORM statement indicates that a field length of seven columns should be used (the field length must be long enough room to include both the decimal point and the decimal digits), and that the number to be printed should have two decimal places.  The actual number is then rounded to the number of decimal places specified:

The N and C specifications can be used in the same statement:

You may also specify the printing of literal directly from within the FORM statement.  Also, a single FORM statement may be referenced by more than one PRINT USING statement.  The following example, which uses the same FORM statement to print three different lines, shows how PRINT USING and FORM can be used to print large amounts of data that is to appear in the same format:

Quick Quiz 7.8

1. FORM statement specifications can accomplish one of two functions.  Identify the two functions from the following four choices:
a) Print numeric strings.
b) Change the cursor position.
c) Print character strings.
d) Indicate that a particular type of data item (either string or numeric) is to be printed at the current cursor position.

2. Which two of the following statements is true about the field length specification?
a) Indicates the amount of space to be allotted to a character or numeric string.
b) Cannot indicate a field length of greater than 15 columns.
c) Directly follows the C and N conversion specifications.

3. What does Business Rules! do with extra spaces in a field containing a numeric value?
a) Inserts one space before and one space after the value.
b) Puts all the spaces to the left of the variable.
c) Ignores extra spaces.

4. Which of the following FORM statements would print the number 890.546 just as it appears here?
a)            00010 FORM N 3.3
b)            00020 FORM N 6.3
c)            00030 FORM n 7.3  

5. True or False: When PRINT with the USING option and the FORM statement are used together, all information to be printed must be included in the PRINT USING statement.
Answers 7.8

Mid-Chapter Practice:

Once again, use NEWSAL and create a FORM statement to print the new salaries in different positions on the screen.

7.9 PIC Conversion specification

One other conversion specification that we will discuss is PIC.  PIC allows you to insert symbols such as dollar signs, commas or decimal places into a number by telling Business Rules! to print the data item according to the picture specified in parentheses.

In the following example, the PIC specification tells Business Rules! to change the number in the PRINT USING statement to a dollar amount. 

The dollar signs are special characters that operate both as insertion characters and as digit identifiers.  As insertion characters, they tell the system to insert one dollar sign just before the first digit in the number. As digit identifiers, they tell the system to put a digit from the number to be printed in their places.  If there are more digit identifiers than there are digits (as in the following case, where there are six dollar signs and only four digits), Business Rules! prints a space instead of the extras.

The comma and the period which appear within the parentheses are insertion characters.  Most characters on your keyboard (except Z, #, B, CR, DR, and DB) can be used as insertion characters, but these are two of the most common.  (Other common characters include the - and + symbols.)  The pound signs (##) appearing after the period are more digit identifiers.  Number signs tell the system to print a digit at that spot even if it must be a zero.

One other symbol, the asterisk, can also be used as both a digit identifier and an insertion character.  It is most often used when printing amounts on checks.  It differs from the dollar sign in that all the symbols are either printed or replaced with stars; none are replaced with spaces.  (The asterisk should only be used in positions to the left of the decimal point.)

The PIC conversion specification allows you to use all of the symbols in the following chart.  Many of these are not discussed in the above section, but a brief description is included here for your reference.

Symbols and Functions

$ - Inserts a dollar sign.  When more than one is used, indicates that digits from the number to be printed are to take their place.  Extra symbols (those not replaced with a number or printed as a dollar sign) are replaced with spaces when formatted.
, Inserts a comma where specified.
. Inserts a decimal point where specified.  Indicates that all digits to the right of this position are decimal characters.
- Inserts a minus sign where specified.  Also serves as a digit identifier when used in multiples. Extra symbols are replaced with spaces when formatted.
+ Inserts a plus sign where specified.  Also serves as a digit identifier when used in multiples. Extra symbols are replaced with spaces when formatted.
* Inserts an asterisk sign where specified.  Also serves as a digit identifier when used in multiples. Extra symbols are printed (not replaced with spaces) when formatted.
# Digit identifier.  Indicates that a digit is to be printed at that spot even if the digit is zero. (Recommended for most decimal place usages.)
B Inserts a blank space where specified.
CR Credit insertion character. Printed only when the number is negative.
DR Debit insertion character. Printed only when the number is negative.
DB Debit insertion character. Printed only when the number is negative.
Z Digit identifier used for zero suppression. Leading zeros are always suppressed.  Digits and decimal digits (including zero) are printed only when the entire number is nonzero.

Quick Quiz 7.9

1. What does the PIC conversion specification do?
a) Tells Business Rules! to print a number according to the picture specified within parentheses.
b) Tells Business Rules! to pick three conversion specifications and format them.
c) Tells Business Rules! to move the cursor to the specified position.

2. What is an insertion character?
a) A character used in the PIC specification that is later inserted in a formatted number.
b) The # sign.
c) A character that is inserted in a program line after the line was already written.

3. What is a digit identifier?
a) Either the + or - signs, which are used to signify that a digit is about to be printed.
b) A special character used with PIC that tells the system it should be replaced with one digit from the number to be printed.
c) Any of the following digits: 0,1,2,3,4,5,6,7,8, or 9.

Answers 7.9

Mid-Chapter Practice:

Finally, use PIC to print the dollar sign and commas appropriately with your salary figures in NEWSAL.

7.10 Changing cursor position

The FORM statement’s conversion specifications, described in the above two lessons, allow you to specify the length or a “picture” of the information to be printed.  When Business Rules! encounters a conversion specification, it begins printing the information at whatever spot the cursor currently occupies.  Because of this, fields will always start from the first column and be placed back-to-back unless you change the cursor position with one of three options: POS, X, or SKIP.

Changing Cursor position with POS

With the POS option, you can specify the exact column position to which the cursor must go.  The following statement, for instance, changes the cursor position to column 56, and then uses the PIC specification to print a check amount.  Notice that the PRINT USING statement occurs after the FORM statement in this case.  Business Rules! looks at the PRINT USING statement line-ref to determine which FORM statement to use, so the two different statements can appear in any order and at any interval.

(The $ symbol begins in Column 56)

Changing Cursor position with X

The X option tells Business Rules! to jump past the number of spaces which is specified just after the X.  The following example prints a data item in column one, then jumps past the 10 columns specified with X 10 and prints a data item in column 24.

Changing or Keeping Cursor position with SKIP

The SKIP option works like pressing ENTER: it moves the cursor down the specified number of rows and back to column one. In the following example, a number is printed with PIC, then SKIP 1 returns the cursor to the first position in the next line and another number with a leading minus sign is printed.  A second SKIP again returns the cursor to the next line, where a bar (which serves as an = sign) is printed.  A third SKIP brings the cursor down again; the difference between the first two numbers is then printed and followed by the word TOTAL:

Using cursor position specifications without conversion specifications Except in one or two unusual cases, FORM’s cursor position specifications should always be followed with a conversion specification that prints a specific piece of information.  In the example below, a PRINT USING statement specifies that the FORM statement at line 20 should be used to print the specified data.  When Business Rules! goes to line 20 though, it finds that there are more data items than there are conversion specifications.  Zippy the Cursor thinks this is no big deal: he’ll just go back to the beginning of the FORM statement and use the same specifications over until all the data items are printed. File:7.9g.png

Where there is one conversion specification, Zippy uses the same FORM statement multiple times, and gets everything printed.

In this next example, an error occurs. Can you tell what the problem is and how to fix it? File:7.9h.png

(It’s missing an output specification). To print the months at intervals of 10 spaces, one possible solution is shown below. Notice that when N or C is not followed by a number, any size string can follow it.

Quick Quiz 7.10

1. Conversion specifications tell Business Rules! to print a data item at which cursor position?

a) Column 1.
b) The current cursor position.
c) The column after the current cursor position.

2. A FORM statement must always be placed immediately after a PRINT USING statement, True or False?

3. What does the POS option of the FORM statement do?

a) Tells Business Rules! to print a data item at the specified column position.
b) Tells Business Rules! to move the cursor past the specified number of columns.
c) Tells Business Rules! to move the cursor to the specified column position.

4. What does the X option of the FORM statement do?

a) Tells Business Rules! to move the cursor past the specified number of columns.
b) Tells Business Rules! to erase the specified number of characters.
c) Tells Business Rules! to print a data item at the specified column position.

5. What does the SKIP option of the FORM statement do?

a) Tells Business Rules! to print the specified data items in bold face.
b) Tells Business Rules! to move the cursor past the specified number of columns.
c) Tells Business Rules! to move the cursor back to column one and down the specified number of rows.

6. What happens when the PRINT USING statement specifies more data items than the FORM statement has conversion specifications?

a) Business Rules! enters an infinite loop.
b) Business Rules! continues executing the FORM statement until all the data items are printed.
c) Business Rules! prints as many data items as there are conversion specifications, then goes on to the next program line.

Answers 7.10

Chapter 7 Challenge:

Once again, use NEWSAL and put everything from this chapter together to print the salaries as shown below:

Solution

NEXT:FOR/NEXT and ON GOTO

Back to Index