home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / database / rptform.zip / REPORT5 < prev   
Text File  |  1987-04-16  |  12KB  |  278 lines

  1.                    REPORT FORM - The dBASE REPORT GENERATOR
  2.                    ========================================
  3.  
  4.                                    Part 5
  5.  
  6.  
  7.  
  8.  
  9.  
  10. Last month we looked at some of the ways printer control codes and the
  11. dBASE CHR() function can be used to create printed reports with an elegant
  12. appearance.  As promised, this month we'll continue by exploring how
  13. printer control codes can be included inside the REPORT FORM itself to
  14. change print styles in specified portions of a report, print column
  15. headings in differing print styles, bold or with underline, and use just
  16. about any other feature your printer provides.
  17.  
  18. I want to reiterate that different printers often use different printer
  19. control codes to accomplish the same thing, therefore your printer may not
  20. use the specific codes I use as examples in this column.
  21.  
  22. For illustration purposes I will continue to use control codes for the
  23. Toshiba P351 and P351C printers and control codes that work with most Epson
  24. printers.  Okidata and IBM printers often use the same printer control
  25. codes as the generic Epson ones used here, but since I don't have either of
  26. those printers available (nor their manuals) to test I can not promise all
  27. the generic Epson examples will work with Okidatas and IBMs.
  28.  
  29. Most printer manuals have a section - or even a chart - giving the Escape
  30. Sequences, Hexadecimal (HEX) and Decimal (DEC) values for the printer
  31. control codes.  You need to look for the Decimal values.  Those are the
  32. numbers that will be placed in the dBASE CHR() function.
  33.  
  34. Now on to the really fancy stuff!
  35.  
  36. Using the dBASE CHR() function, printer control codes can be sent to the
  37. printer from within the REPORT FORM by placing them in the expression you
  38. define in the field contents block, just as you would place a data field
  39. there.  As before, the actual numeric values used would depend upon your
  40. particular printer and must be obtained from your printer manual.
  41.  
  42. The printer control codes can be placed in any definition field, including
  43. subgroup totals and sub-subgroup totals, EXCEPT the page and column heading
  44. definition fields.  But there is even a way to trick dBASE and FoxBASE into
  45. doing that.
  46.  
  47. Printer control codes can be applied to an entire report or just part of a
  48. REPORT FORM report.  This all gets a little tricky as we create more
  49. complex print-outs with REPORT FORM, so let's start off with an easy
  50. example.
  51.  
  52.  
  53. Assume only one field of a particular report is to be printed in bold or
  54. emphasized print.  The printer control code to turn on the bold print would
  55. be placed in the block for defining a column, then you would enter the name
  56. of the data field, and then the control code to turn off the bold print.  
  57.  
  58. For most Epson printers the information you place in the column definition
  59. block in the "Contents" area would be:
  60.  
  61.         CHR(27) + CHR(69) + <datafield> + CHR(27) + CHR(70)
  62.  
  63. while you would use the following for the Toshiba P351 and P351C printers:
  64.  
  65.         CHR(27) + CHR(75) + <datafield> + CHR(27) + CHR(77)
  66.  
  67. In other words, the information in that column definition in REPORT FORM is
  68. saying to the printer "Turn on the bold print, print the contents of the
  69. data field, then turn off the bold print.  Now go on and print the informa-
  70. tion in the next column [with the bold print off]."
  71.  
  72. As with the examples given last month for the optional heading feature, you
  73. can combine multiple printer commands in one column definition block.  And
  74. you can place them in various places within the column definition block of
  75. REPORT FORM.
  76.  
  77. To use a somewhat uncomplicated example of this, let's assume we have a
  78. report where we would like the FIRSTNAME field printed normally and the
  79. LASTNAME field printed in bold or emphasized.  For most Epson printers the
  80. following would be placed in the contents area of the column definition
  81. block:
  82.  
  83.         TRIM(FIRSTNAME) + " "  + CHR(27) + CHR(69) + LASTNAME;
  84.           + CHR(27) + CHR(70)
  85.  
  86. and for the Toshiba P351 and P351C printers you would use this code:
  87.  
  88.         TRIM(FIRSTNAME) + " " + CHR(27) + CHR(75) + LASTNAME;
  89.           + CHR(27) + CHR(77)
  90.  
  91. Getting a bit fancier, let's try a REPORT FORM where one particular column
  92. has information on the department (DEPT), FIRSTNAME and LASTNAME.  Within
  93. the column we want the DEPT field on one line, underlined and in bold, and
  94. on the next line in the column we want the lastname printed first in bold,
  95. then the first name printed in normal type.  And we want all of this in-
  96. formation aligned within the column.
  97.  
  98. For the unwary, the trick to this is aligning everything properly.  Since
  99. the CHR() printer control codes are not "printable" most printers produce a
  100. blank space on the paper when the printer code is encountered.  A CHR(27) +
  101. CHR(69) would produce one blank space, for example.
  102.  
  103. As we saw in previous months, the semi-colon enclosed in quotation marks
  104. produces multiple data lines in REPORT FORM.
  105.  
  106. The way we would produce our column on most Epson printers would be by
  107. placing the following statement in the contents of the column definition
  108. block:
  109.  
  110.         CHR(27) + CHR(69) + CHR(27) + CHR(45) + DEPT + CHR(27);
  111.           + CHR(45) + ";" SPACE(2) + TRIM(LASTNAME) + "," + CHR(27) +;
  112.           CHR(70) + FIRSTNAME
  113.  
  114. and for the Toshiba P351 and P351C printers the statement would be:
  115.  
  116.         CHR(27) + CHR(75) + CHR(27) + CHR(73) + DEPT + CHR(27);
  117.           + CHR(74) + ";" + SPACE(2) + TRIM(LASTNAME) + "," + CHR(27) +;
  118.           CHR(77) + FIRSTNAME
  119.  
  120.  
  121. At first this might look a little crazy, so let's take it apart and examine
  122. it more thoroughly.  To begin the column we have two printer control codes,
  123. one to turn on the bold and another to turn on the underlining.  This means
  124. the printer will "print" two blank spaces in the column before printing the
  125. information in the DEPT field.
  126.  
  127. After the data from the DEPT field is printed in bold and underlined the
  128. printer control code to turn off the underlining feature is then issued. 
  129. This results in another blank space on the paper but does not really effect
  130. the left aligning of data because the next instruction is the semi-colon in
  131. quotation marks which instructs the printer to print the next information
  132. on the next line.
  133.  
  134. Immediately after the instruction to print the next pieces of information
  135. on the next line we have inserted a SPACE(2) command, so the printer will
  136. "print" two blank spaces before beginning to print the trimmed LASTNAME
  137. data.  That then left aligns the printed LASTNAME with the information from
  138. the DEPT field on the previous line.  Information for LASTNAME will be
  139. printed in bold but without underlining.
  140.  
  141. The next instruction is to print a comma immediately after the trimmed last
  142. name.  Normally the instruction would be to insert a comma and a space and
  143. then print the FIRSTNAME.  But in this case we have entered another printer
  144. control code to turn off the bold print immediately after the comma and
  145. this control code produces a blank space, so we don't need to use that
  146. extra space in our instructions.  
  147.  
  148. The last instruction for this particular column then is to print the data
  149. in the FIRSTNAME field.  Since underlining and bold have both been turned
  150. off, the information from FIRSTNAME will be printed in the printer's
  151. default type.
  152.  
  153. If you have managed to follow all of this you have probably realized by now
  154. my first example used a space (or " ") where it was not really necessary
  155. and the actual printed report would end up with two blank spaces between
  156. the FIRSTNAME and LASTNAME.  OK - you're right - but worse things have been
  157. known to happen.  I just didn't want to confuse the issue at that point.
  158.  
  159.  
  160. If you're not thoroughly confused by now, take a deep breath because we're
  161. about to plunge into the most convoluted of the REPORT FORM printing
  162. tricks.
  163.  
  164. As I mentioned earlier, dBASE and FoxBASE won't let you put printer control
  165. codes in the blocks where you define the page headings and column headings
  166. for the reports produced by REPORT FORM.  But you can trick them into doing
  167. the same thing anyway when you want to, for instance, have all column
  168. headings printed in bold on each page or have each page heading printed in
  169. bold (or bold and underlined for that matter).
  170.  
  171. Let's assume we are constructing a REPORT FORM in which we want all the
  172. column headings printed in bold type.
  173.  
  174. When you define the contents of your REPORT FORM include the printer
  175. control codes to turn OFF the print attribute in the contents of the FIRST
  176. column to be printed.  (That's right, turn OFF the bold, underline or
  177. whatever.)
  178.  
  179. The contents of the first column of your REPORT FORM would begin with the
  180. following for most Epson printers:
  181.  
  182.         CHR(27) + CHR(70) + <datafield>
  183.  
  184. and for the Toshiba P351 and P351C printers:
  185.  
  186.         CHR(27) + CHR(77) + <datafield>
  187.  
  188. Next, in the LAST column to be printed on the page include the printer
  189. control codes to turn ON the bold print immediately after you enter the
  190. field definition(s) to be printed.  For most Epsons it would be:
  191.  
  192.         <datafield> + CHR(27) + CHR(69)
  193.  
  194. and for the Toshiba P351 and P351C printers:
  195.  
  196.         <datafield> + CHR(27) + CHR(75)
  197.  
  198. The last piece of this puzzle requires you to send the printer control
  199. codes to turn ON the desired print attribute (in this case the bold print)
  200. before issued the REPORT FORM xxxxx TO PRINT command.
  201.  
  202. With all the pieces of the puzzle in place, it works out this way: (a) Set
  203. the bold print on; (b) print the column/page headings; (c) sent the bold
  204. print off and print the contents of the data fields; (d) set the bold print
  205. on after the last column has been printed.
  206.  
  207. If you are confused, try following the instructions through and it may
  208. begin to make sense.  
  209.  
  210.  
  211.  
  212. After you have created your REPORT FORM the command code would look like
  213. this for most Epson printers:
  214.  
  215.         USE <database> INDEX <whatever>
  216.         SET PRINT ON
  217.         ?? CHR(27) + CHR(69)                 && Set bold ON
  218.         REPORT FORM xxxxx NOEJECT TO PRINT
  219.         EJECT
  220.         ?? CHR(27) + CHR(70)                 && Set bold OFF
  221.         SET PRINT OFF
  222.         CLOSE DATABASES
  223.     
  224.  
  225. while the Toshiba P351 and P351C printers would need the following:
  226.  
  227.         USE <database> INDEX <whatever>
  228.         SET PRINT ON
  229.         ?? CHR(27) + CHR(75)                 && Set bold ON
  230.         REPORT FORM xxxxx NOEJECT TO PRINT
  231.         EJECT
  232.         ?? CHR(27) + CHR(77)                 && Set bold OFF
  233.         SET PRINT OFF
  234.         CLOSE DATABASES
  235.  
  236.  
  237. Printer control codes can, by the way, be used in a similar way when you
  238. LIST TO PRINT or perform other print jobs that do not use the REPORT FORM
  239. report generator.   
  240.  
  241. One last little touch.  Instead of having the information being sent to the
  242. printer also scroll on screen, try flashing up a screen that says something
  243. similar to "REPORT PRINTING..." and then SET CONSOLE OFF.  When the report
  244. has finished printing SET CONSOLE ON again.  
  245.  
  246. Since reports often use more than the 80 column display available on most
  247. monitors the material scrolling past on the screen often looks like so much
  248. garbage and confuses or alarms unwary users.  The SET CONSOLE OFF method
  249. provides a much neater approach.  It would go something like this:
  250.  
  251.         USE <database> INDEX <whatever>
  252.         SET COLOR TO W/N
  253.         CLEAR
  254.         SET COLOR TO +BR/N
  255.         @ 04,20 TO 11,56 DOUBLE
  256.         SET COLOR TO +GR/N
  257.         @ 05,21 CLEAR TO 10,55
  258.         @ 06,30 SAY "REPORT PRINTING..."
  259.         @ 08,25 SAY "PLEASE DO NOT TOUCH KEYBOARD"
  260.         SET CONSOLE OFF
  261.         SET PRINT ON
  262.         ?? CHR(27) + CHR(69)                 && Set bold ON - most Epsons
  263.         REPORT FORM xxxxx NOEJECT TO PRINT
  264.         EJECT
  265.         ?? CHR(27) + CHR(70)                 && Set bold OFF
  266.         SET PRINT OFF
  267.         SET CONSOLE ON
  268.         SET COLOR TO BG+/N
  269.         @ 21,0 CLEAR
  270.         WAIT "REPORT COMPLETED.  Press any key to continue..." TO NEXT
  271.         CLOSE DATABASES
  272.         RETURN
  273.  
  274.  
  275.  
  276.  
  277.  
  278.