home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / DATABASE / SCR2FRG.ZIP / SCR2FRG.DOC < prev    next >
Text File  |  1990-05-14  |  12KB  |  260 lines

  1.    This article is reprinted from the March 1990 edition of
  2. TechNotes/dBASE IV  Due to the limitations of this media, certain
  3. graphic elements such as screen shots, illustrations and some tables
  4. have been omitted.  Where possible, reference to such items has been
  5. deleted.  As a result, continuity may be compromised.  
  6.  
  7. TechNotes is a monthly publication from the Ashton-Tate Software
  8. Support Center.  For subscription information, call 213-538-6060.
  9.  
  10.  
  11. ====================================================================
  12.  
  13.  
  14. What Were Once Screens 
  15. Are Now Reports
  16. ---------------
  17. Copy of the March 1990 issue Ashton-Tate's Technotes magazine
  18.  
  19. By BRYAN FLYNN
  20.  
  21. Editors Note:
  22.  
  23. Since this article discusses the use of .GEN files and Template
  24. Language, you will need  the Template Language compiler and
  25. documentation which is included only with the  Developer's
  26. Edition of dBASE IV.  For those with the standard edition, you
  27. may take  advantage of this new .GEN file, Scr2Frg.GEN, which
  28. creates reports from existing screen forms  without the need for
  29. programming, by accessing the Ashton-Tate Bulletin Board,
  30. CompuServe, or GEnie. 
  31.  
  32. One of the strengths of dBASE IV is the
  33. What-You-See-Is-What-You-Get (WYSIWYG)  approach of creating
  34. Reports (.FRM files) and Screen Forms (.SCR files).  Many times,
  35. a report  that duplicates a screen form is needed.  For instance,
  36. a hard copy of a data entry record is a  typical example.
  37.  
  38. There are three ways to create a report from a screen form.  One
  39. way is to create a report  that looks exactly like your screen
  40. form.  However, if your screen form is fairly complex, this 
  41. could be a redundant, time consuming affair.  Another way is to
  42. incorporate a copy of the .FMT  code created when you saved your
  43. screen form into a program.  This requires programming  knowledge
  44. which could find you spending more time converting and less time
  45. producing results.
  46.  
  47. You might ponder, "Wouldn't it be nice if dBASE IV did this for
  48. me  automatically?"   Since the layout is already there, why
  49. can't dBASE IV do it?  Well, good news!  It can!  That's  the
  50. third and most desirable solution and the point of this article.
  51.  
  52. The easy solution to the above problem is to have a dBASE IV
  53. template do the work for  us.  The template source code presented
  54. at the end of this article will take an existing screen  form
  55. (.SCR) and generate a report form file (.FRG).   This report file
  56. can then be used in  conjunction with the REPORT FORM command or
  57. run from the Control Center.  
  58.  
  59. A Brief Explanation of the Template Language
  60.  
  61. The Template Language takes dBASE IV design files (in our case
  62. the .SCR file) and  generates either documentation or program
  63. versions of these objects via the Template Language  Compiler. 
  64. Other design sources include .FRM, .LBL, .BCH, .APP, .POP and
  65. .BAR files.
  66.  
  67. Consider each design file as a stack of items.  For example, a
  68. screen form can contain a  stack of items consisting of fields,
  69. boxes, text, memory variables, and calculated fields.  Each of 
  70. these items have certain attributes such as row and column
  71. position, display length, data type,  and other specific
  72. attributes.  Attribute descriptions of these items are kept in
  73. definition files  (.DEF files).  The definition file for screen
  74. forms is called FORM.DEF.
  75.  
  76. The Template Language enables you to retrieve items from these
  77. design files, examine  them, and generate code depending upon the
  78. items examined.  When you create a screen form,  dBASE IV
  79. retrieves the stack of items contained in the .SCR file, passes
  80. it through FORM.GEN  and generates a .FMT file (called a format
  81. file).  
  82.  
  83. The Template Language contains tools, consisting of control
  84. structures, file handling  capabilities, and functions to scan
  85. through a design file and determine what is outputted.   These
  86. tools are used to create Template Language programs.  The source
  87. code for Template  Language programs are kept in .COD files. 
  88. These .COD files are then compiled into .GEN files.   Using
  89. Template Language, you can create your own custom made .GEN files
  90. and control the  dBASE IV code outputted when generating labels,
  91. reports, APGEN Applications, and Screen  Forms.
  92.  
  93. There are a number of existing .COD files in your DTL directory
  94. that can be used freely as  examples or building blocks for your
  95. own .COD files.  If you haven't installed them, check the 
  96. contents of your Template Language disks.
  97.  
  98. There are two basic steps to creating a .GEN file:
  99.  
  100. 1.      Write the source code (.COD file) for the .GEN file using
  101.         a text editor 
  102. 2.      Compile the .COD file into a .GEN file using the DTC.EXE
  103.         program. dBASE IV uses these default template names to
  104.         create the related code and object files for the 
  105.         following: 
  106.  
  107. *Labels:   LABEL.GEN
  108. *Reports:  REPORT.GEN
  109. * AppsGen:  MENU.GEN
  110. *Screens:  FORM.GEN
  111.  
  112. The .COD files that generated these files are called LABEL.COD,
  113. REPORT.COD,  AS_MENU.COD and FORM.COD respectively.
  114.  
  115. Please note that any existing  report file with the same name as
  116. your screen form will be  overwritten.  If you have an existing
  117. report with the same name as your screen, it is important  to
  118. first copy your .SCR file to a new name so that it will not
  119. conflict with the similarly named  report.
  120.  
  121. A more complete explanation of the Template Language can be found
  122. in the Developer's  Edition manual entitled Using the Template
  123. Language.
  124.  
  125. How to use Scr2Frg.GEN
  126.  
  127. Begin by either typing in the listed template code at the end of
  128. this article or retrieving it  from the Ashton-Tate Electronic
  129. Bulletin Board.  Compile it by entering at the DOS prompt:
  130.  
  131. DTC -iScr2Frg.COD
  132.  
  133. DTC.EXE is the Template Compiler which comes with the dBASE IV
  134. Developer's  Edition.
  135.  
  136. The "-i" parameter prefaces the file being submitted to the
  137. compiler, indicating it as the  input file.  Once Scr2Frg.COD is
  138. successfully compiled, a file named Scr2Frg.GEN will exist.  
  139. Copy the .GEN file (Scr2Frg.GEN) into your dBASE IV directory, if
  140. it doesn't already reside  there.
  141.  
  142. You're now ready to generate a new .FRG file from an existing
  143. screen form. At the DOS prompt enter:
  144.  
  145. SET DTL_FORM=Scr2Frg.GEN
  146.  
  147. This specifies dBASE IV to use the Scr2Frg.GEN file instead of
  148. the default FORM.GEN.  Now  go into dBASE IV and modify the
  149. screen form from which you want to create a report.  Once  you're
  150. in the layout screen, press Ctrl-End.  This will force
  151. regeneration of your design screen and  create a new .FRG file by
  152. the same name as that screen.
  153.  
  154. It is important that the SET DTL command, which sets a DOS
  155. environmental variable, not  be executed while in a DOS access of
  156. a dBASE IV session.  A DOS access is a copy of the  environment
  157. and not a return to the original DOS environment which exists
  158. before and after a  dBASE IV session.  Therefore, any SET command
  159. would be eliminated upon the return to dBASE  IV via the DOS
  160. access.
  161.  
  162. Points to consider
  163.  
  164. If the screen you're regenerating does not have an existing .FMT
  165. file, the error message  "File could not be found" will appear. 
  166. The error appears because dBASE IV tries to compile a  .FMT file
  167. any time you save a screen.  If one doesn't exist, the above
  168. error message appears  which may be ignored.
  169.  
  170. After generation, you can then run the .FRG file from either the
  171. Control Center or the dot  prompt as if it were a regular
  172. report.  If you want to place the new report in the Control
  173. Center,  you must first run the report initially from the dot
  174. prompt.  The reason for this is that the  Control Center will
  175. only let you add .FRM or .FRO (the interface and object) files
  176. and the  Scr2Frg.GEN template file creates only a .FRG (program
  177. code) file.  Running the report with  the REPORT FORM command 
  178. will automatically create a .FMO file.  
  179.  
  180. One point that may not be obvious to newer users is that no
  181. design file (.FRM)  is created.   The report you create using the
  182. Scr2Frg.GEN file cannot be modified via MODIFY REPORT  since the
  183. initial design data was from the screen form.
  184.  
  185. Scr2Frg.COD Usage Notes
  186. *       Scr2Frg will create a report that looks exactly like your
  187.         screen (except for the status bar).   This also includes
  188.         memos in windows looking exactly the same.   
  189. *       After each record, a page eject will occur.   
  190. *       A screen will always take up a minimum of either 25 or 43
  191.         lines depending upon what  display mode dBASE IV was in
  192.         when the screen report was generated.  Consequently, even
  193.         a  screen with one line of information will generate 25
  194.         to 43 lines when printed. 
  195. *        If you would like to print more than one screen per
  196.         page, you'll need to adjust the system  memory variables
  197.         _plength and _padvance.  _plength specifies your page
  198.         length and  _padvance specifies whether to advance the
  199.         paper with either line feeds or a form feed.  
  200.         
  201.         Example: Your screen is 25 lines in length and your
  202.         physical page length is 66 lines.  To place  two screens
  203.         per page, set  plength to 33 and _padvance to "Linefeeds"
  204.         (instead of the default  "Formfeed").  This will place
  205.         one screen for each 33 lines.  
  206.         
  207.         These two variables can either be set from the dot
  208.         prompt, in a program, or from the Print  menu.  When
  209.         setting these from the Print menu, page length would be
  210.         set under the Print:  Page dimensions menu.  The method
  211.         of advancing a page (formfeed vs. linefeeds)  would be 
  212.         set from the Print: Control of printer menu.    
  213. *       The line number on which item numbers are placed when
  214.         creating a screen is respected.  This  means that an item
  215.         on the 26th line of a two screen screen form will print
  216.         on the 26th line of  the report and not on a separate
  217.         page. 
  218. *       A heading can be specified with the REPORT FORM command,
  219.         using the HEADING  parameter, and will appear at the top
  220.         of each page.  The number of lines in the heading will 
  221.         be added on to the screen size.  Suppose you have a three
  222.         line header and you're printing a 25  line screen.  The
  223.         total number of lines needed to print each record would
  224.         then be 28. 
  225. *       The PLAIN and SUMMARY options of the REPORT FORM command
  226.         are ignored except  where PLAIN is included with the
  227.         HEADING option.  These two options are mutually 
  228.         exclusive with the PLAIN option taking precedence.    
  229. *       An optional page break will be inserted on whatever line
  230.         desired if that line has  .PB in the  first column.  This
  231.         feature could be helpful if, for instance, you have a
  232.         four page screen form  and you'd like everything after a
  233.         certain line to appear on a new page.  To use, simply
  234.         type  .PB in the first column on the line you want to
  235.         begin the next page.  The next time you  regenerate your
  236.         screen with the Scr2Frg.GEN template active, a report
  237.         will be generated  with a page break at that point.  Do
  238.         not specify a page break while a  box is printing as 
  239.         defined boxes will not respect a page break. 
  240. *       When finished generating reports from screen forms by
  241.         using Scr2Frg.GEN, make sure to set  your form template
  242.         back to its default.  This is done by entering at the DOS
  243.         prompt:
  244.     
  245.     SET DTL_FORM=
  246.     
  247. Since nothing is specified after the equal sign, DTL_FORM is
  248. erased from memory and the  default FORM.GEN will now be assumed.
  249.  
  250. The Scr2Frg.GEN file is just one example of how a feature can be
  251. added to the  product simply by using the appropriate template
  252. and represents a very useful  flexibility of dBASE IV.  Remember
  253. that custom made templates can be as simple  or complex as you
  254. wish and while it might take some time to write a template,  the
  255. time saved in developing a system or the added flexibility to a
  256. system could  more than compensate.
  257.  
  258.  
  259.  
  260.