REPORT FORM - The dBASE REPORT GENERATOR Part 5

                    REPORT FORM - The dBASE REPORT GENERATOR

                   ========================================


                                   Part 5






Last month we looked at some of the ways printer control codes and the

dBASE CHR() function can be used to create printed reports with an elegant

appearance.  As promised, this month we'll continue by exploring how

printer control codes can be included inside the REPORT FORM itself to

change print styles in specified portions of a report, print column

headings in differing print styles, bold or with underline, and use just

about any other feature your printer provides.


I want to reiterate that different printers often use different printer

control codes to accomplish the same thing, therefore your printer may not

use the specific codes I use as examples in this column.


For illustration purposes I will continue to use control codes for the

Toshiba P351 and P351C printers and control codes that work with most Epson

printers.  Okidata and IBM printers often use the same printer control

codes as the generic Epson ones used here, but since I don't have either of

those printers available (nor their manuals) to test I can not promise all

the generic Epson examples will work with Okidatas and IBMs.


Most printer manuals have a section - or even a chart - giving the Escape

Sequences, Hexadecimal (HEX) and Decimal (DEC) values for the printer

control codes.  You need to look for the Decimal values.  Those are the

numbers that will be placed in the dBASE CHR() function.


Now on to the really fancy stuff!


Using the dBASE CHR() function, printer control codes can be sent to the

printer from within the REPORT FORM by placing them in the expression you

define in the field contents block, just as you would place a data field

there.  As before, the actual numeric values used would depend upon your

particular printer and must be obtained from your printer manual.


The printer control codes can be placed in any definition field, including

subgroup totals and sub-subgroup totals, EXCEPT the page and column heading

definition fields.  But there is even a way to trick dBASE and FoxBASE into

doing that.


Printer control codes can be applied to an entire report or just part of a

REPORT FORM report.  This all gets a little tricky as we create more

complex print-outs with REPORT FORM, so let's start off with an easy

example.


Assume only one field of a particular report is to be printed in bold or

emphasized print.  The printer control code to turn on the bold print would

be placed in the block for defining a column, then you would enter the name

of the data field, and then the control code to turn off the bold print.  


For most Epson printers the information you place in the column definition

block in the "Contents" area would be:


        CHR(27) + CHR(69) + <datafield> + CHR(27) + CHR(70)


while you would use the following for the Toshiba P351 and P351C printers:


        CHR(27) + CHR(75) + <datafield> + CHR(27) + CHR(77)


In other words, the information in that column definition in REPORT FORM is

saying to the printer "Turn on the bold print, print the contents of the

data field, then turn off the bold print.  Now go on and print the informa-

tion in the next column [with the bold print off]."


As with the examples given last month for the optional heading feature, you

can combine multiple printer commands in one column definition block.  And

you can place them in various places within the column definition block of

REPORT FORM.


To use a somewhat uncomplicated example of this, let's assume we have a

report where we would like the FIRSTNAME field printed normally and the

LASTNAME field printed in bold or emphasized.  For most Epson printers the

following would be placed in the contents area of the column definition

block:


        TRIM(FIRSTNAME) + " "  + CHR(27) + CHR(69) + LASTNAME;

          + CHR(27) + CHR(70)


and for the Toshiba P351 and P351C printers you would use this code:


        TRIM(FIRSTNAME) + " " + CHR(27) + CHR(75) + LASTNAME;

          + CHR(27) + CHR(77)


Getting a bit fancier, let's try a REPORT FORM where one particular column

has information on the department (DEPT), FIRSTNAME and LASTNAME.  Within

the column we want the DEPT field on one line, underlined and in bold, and

on the next line in the column we want the lastname printed first in bold,

then the first name printed in normal type.  And we want all of this in-

formation aligned within the column.


For the unwary, the trick to this is aligning everything properly.  Since

the CHR() printer control codes are not "printable" most printers produce a

blank space on the paper when the printer code is encountered.  A CHR(27) +

CHR(69) would produce one blank space, for example.


As we saw in previous months, the semi-colon enclosed in quotation marks

produces multiple data lines in REPORT FORM.


The way we would produce our column on most Epson printers would be by

placing the following statement in the contents of the column definition

block:


        CHR(27) + CHR(69) + CHR(27) + CHR(45) + DEPT + CHR(27);

          + CHR(45) + ";" SPACE(2) + TRIM(LASTNAME) + "," + CHR(27) +;

          CHR(70) + FIRSTNAME


and for the Toshiba P351 and P351C printers the statement would be:


        CHR(27) + CHR(75) + CHR(27) + CHR(73) + DEPT + CHR(27);

          + CHR(74) + ";" + SPACE(2) + TRIM(LASTNAME) + "," + CHR(27) +;

          CHR(77) + FIRSTNAME



At first this might look a little crazy, so let's take it apart and examine

it more thoroughly.  To begin the column we have two printer control codes,

one to turn on the bold and another to turn on the underlining.  This means

the printer will "print" two blank spaces in the column before printing the

information in the DEPT field.


After the data from the DEPT field is printed in bold and underlined the

printer control code to turn off the underlining feature is then issued. 

This results in another blank space on the paper but does not really effect

the left aligning of data because the next instruction is the semi-colon in

quotation marks which instructs the printer to print the next information

on the next line.


Immediately after the instruction to print the next pieces of information

on the next line we have inserted a SPACE(2) command, so the printer will

"print" two blank spaces before beginning to print the trimmed LASTNAME

data.  That then left aligns the printed LASTNAME with the information from

the DEPT field on the previous line.  Information for LASTNAME will be

printed in bold but without underlining.


The next instruction is to print a comma immediately after the trimmed last

name.  Normally the instruction would be to insert a comma and a space and

then print the FIRSTNAME.  But in this case we have entered another printer

control code to turn off the bold print immediately after the comma and

this control code produces a blank space, so we don't need to use that

extra space in our instructions.  


The last instruction for this particular column then is to print the data

in the FIRSTNAME field.  Since underlining and bold have both been turned

off, the information from FIRSTNAME will be printed in the printer's

default type.


If you have managed to follow all of this you have probably realized by now

my first example used a space (or " ") where it was not really necessary

and the actual printed report would end up with two blank spaces between

the FIRSTNAME and LASTNAME.  OK - you're right - but worse things have been

known to happen.  I just didn't want to confuse the issue at that point.



If you're not thoroughly confused by now, take a deep breath because we're

about to plunge into the most convoluted of the REPORT FORM printing

tricks.


As I mentioned earlier, dBASE and FoxBASE won't let you put printer control

codes in the blocks where you define the page headings and column headings

for the reports produced by REPORT FORM.  But you can trick them into doing

the same thing anyway when you want to, for instance, have all column

headings printed in bold on each page or have each page heading printed in

bold (or bold and underlined for that matter).


Let's assume we are constructing a REPORT FORM in which we want all the

column headings printed in bold type.


When you define the contents of your REPORT FORM include the printer

control codes to turn OFF the print attribute in the contents of the FIRST

column to be printed.  (That's right, turn OFF the bold, underline or

whatever.)


The contents of the first column of your REPORT FORM would begin with the

following for most Epson printers:


        CHR(27) + CHR(70) + <datafield>


and for the Toshiba P351 and P351C printers:


        CHR(27) + CHR(77) + <datafield>


Next, in the LAST column to be printed on the page include the printer

control codes to turn ON the bold print immediately after you enter the

field definition(s) to be printed.  For most Epsons it would be:


        <datafield> + CHR(27) + CHR(69)


and for the Toshiba P351 and P351C printers:


        <datafield> + CHR(27) + CHR(75)


The last piece of this puzzle requires you to send the printer control

codes to turn ON the desired print attribute (in this case the bold print)

before issued the REPORT FORM xxxxx TO PRINT command.


With all the pieces of the puzzle in place, it works out this way: (a) Set

the bold print on; (b) print the column/page headings; (c) sent the bold

print off and print the contents of the data fields; (d) set the bold print

on after the last column has been printed.


If you are confused, try following the instructions through and it may

begin to make sense.  



After you have created your REPORT FORM the command code would look like

this for most Epson printers:


        USE <database> INDEX <whatever>

        SET PRINT ON

        ?? CHR(27) + CHR(69)                 && Set bold ON

        REPORT FORM xxxxx NOEJECT TO PRINT

        EJECT

        ?? CHR(27) + CHR(70)                 && Set bold OFF

        SET PRINT OFF

        CLOSE DATABASES

    


while the Toshiba P351 and P351C printers would need the following:


        USE <database> INDEX <whatever>

        SET PRINT ON

        ?? CHR(27) + CHR(75)                 && Set bold ON

        REPORT FORM xxxxx NOEJECT TO PRINT

        EJECT

        ?? CHR(27) + CHR(77)                 && Set bold OFF

        SET PRINT OFF

        CLOSE DATABASES



Printer control codes can, by the way, be used in a similar way when you

LIST TO PRINT or perform other print jobs that do not use the REPORT FORM

report generator.   


One last little touch.  Instead of having the information being sent to the

printer also scroll on screen, try flashing up a screen that says something

similar to "REPORT PRINTING..." and then SET CONSOLE OFF.  When the report

has finished printing SET CONSOLE ON again.  


Since reports often use more than the 80 column display available on most

monitors the material scrolling past on the screen often looks like so much

garbage and confuses or alarms unwary users.  The SET CONSOLE OFF method

provides a much neater approach.  It would go something like this:


        USE <database> INDEX <whatever>

        SET COLOR TO W/N

        CLEAR

        SET COLOR TO +BR/N

        @ 04,20 TO 11,56 DOUBLE

        SET COLOR TO +GR/N

        @ 05,21 CLEAR TO 10,55

        @ 06,30 SAY "REPORT PRINTING..."

        @ 08,25 SAY "PLEASE DO NOT TOUCH KEYBOARD"

        SET CONSOLE OFF

        SET PRINT ON

        ?? CHR(27) + CHR(69)                 && Set bold ON - most Epsons

        REPORT FORM xxxxx NOEJECT TO PRINT

        EJECT

        ?? CHR(27) + CHR(70)                 && Set bold OFF

        SET PRINT OFF

        SET CONSOLE ON

        SET COLOR TO BG+/N

        @ 21,0 CLEAR

        WAIT "REPORT COMPLETED.  Press any key to continue..." TO NEXT

        CLOSE DATABASES

        RETURN








Comments

Popular posts from this blog

BOTTOM LIVE script

Evidence supporting quantum information processing in animals

ARMIES OF CHAOS