home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Database / fdata11.dms / in.adf / FDMacros / FDListMerge < prev    next >
Encoding:
Text File  |  1994-08-17  |  6.6 KB  |  197 lines

  1. /* ============================================================================= */
  2. /* Final Data ARexx Macro.                                                       */
  3. /* FDListMerge - Perform a list merge to a FinalWriter or FinalCopy_II document. */
  4. /* $VER: FDListMerge 1.1 (17.8.94)                                               */
  5. /* © 1994 SoftWood, Inc.                                                         */
  6. /* Use of this macro is strictly at the user's risk.                             */
  7. /*                                                                               */
  8. /* This ARexx macro is to be run from FinalData. It merges a list from a Final   */
  9. /* Data database to a FinalWriter or FinalCopy_II document. To run the macro you */
  10. /* need to have your FC or FW document and your database file both open.         */
  11. /*                                                                               */
  12. /* Before running the macro, place the insertion point in the FinalCopy_II or    */
  13. /* FinalWriter document where you want the list to begin. (Note that this macro  */
  14. /* will use the first FinalWriter or FinalCopy_II port that it can find, so it   */
  15. /* is wise to have only one document window open when you run this macro.        */
  16. /* Otherwise, the wrong document may be used).                                   */
  17. /*                                                                               */
  18. /* Next determine which rows and columns of the database will be put into the    */
  19. /* list. If nothing is selected or a cell is selected, then all rows and columns */
  20. /* will appear in the list. If rows are selected then only those selected rows   */
  21. /* with all the columns will appear. If columns are selected, then all rows but  */
  22. /* only the selected columns will appear in the list. You are now ready to run   */
  23. /* the macro.                                                                    */
  24. /*                                                                               */
  25. /* The macro will ask if you want it to try to set up tab stops. The stops will  */
  26. /* be determined by the column justification and column width. If you choose no, */
  27. /* the macro will use any tabs that might be on the current line. You will also  */
  28. /* be asked if you want to include the column names in the list. If you choose   */
  29. /* yes, then the column names will appear in the first row.                      */
  30. /* ============================================================================= */
  31. OPTIONS RESULTS
  32.  
  33. /* ---- Load the rexxsupport library ---- */
  34. IF ( ADDLIB("rexxsupport.library", 0, -30, 0) = FALSE) THEN EXIT 20
  35.  
  36. /* ---- Get the address of the port we were called from. ---- */
  37. FDPort = ADDRESS()
  38.  
  39. /* ---- Find the address of the word processing port. ------------------- */
  40. /* ---- This will use the first port it can find with the base name. ---- */
  41. /* ---- First try to get a FinalWriter port. If we can't find one, ------ */
  42. /* ---- then try to get a FinalCopy port. ------------------------------- */
  43. WPPortBase = "FINALW."
  44. found = 0
  45. DO p = 1 TO 50
  46.    IF ( SHOWLIST('P', WPPortBase || p) ) THEN DO
  47.       WPPort = WPPortBase || p
  48.       found = 1
  49.       LEAVE
  50.    END
  51. END
  52.  
  53. /* ---- Try FinalCopy port ---- */
  54. IF ( ~ found ) THEN DO
  55.    WPPortBase = "FINALC."
  56.    found = 0
  57.    DO p = 1 TO 50
  58.       IF ( SHOWLIST('P', WPPortBase || p) ) THEN DO
  59.          WPPort = WPPortBase || p
  60.          found = 1
  61.          LEAVE
  62.       END
  63.    END
  64. END
  65.  
  66. IF ( ~ found ) THEN DO
  67.    ShowMessage 1 1 '"Can not find word processing port!" "" "" "OK" "" ""'
  68.    EXIT 10
  69. END
  70.  
  71. DROP p
  72. DROP found
  73.  
  74. /* ---- Determine the number of columns and rows in the database. ---- */
  75. NumRows
  76. nrows = RESULT
  77. NumColumns
  78. ncols = RESULT
  79. IF ( nrows = 0 ) THEN DO
  80.    ShowMessage 1 1 '"No rows of data in database!" "" "" "OK" "" ""'
  81.    EXIT 10
  82. END
  83.  
  84. IF ( ncols = 0 ) THEN DO
  85.    ShowMessage 1 1 '"No columns defined in database!" "" "" "OK" "" ""'
  86.    EXIT 10
  87. END
  88.  
  89. /* ---- Determine which rows and columns will get transferred. ----------- */
  90. /* ---- If selection is OFF or CELL then use all the columns and rows ---- */
  91. firstRow = 1
  92. firstCol = 1
  93. lastRow = nrows
  94. lastCol = ncols
  95. SelectionInfo
  96. PARSE VAR RESULT selType selFrom selTo
  97. SELECT
  98.    WHEN ( selType = "COLUMNS" ) THEN DO
  99.       firstCol = selFrom
  100.       lastCol = selTo
  101.       END
  102.    WHEN ( selType = "ROWS" ) THEN DO
  103.       firstRow = selFrom
  104.       lastRow = selTo
  105.       END
  106.    OTHERWISE DO   /* OFF or CELL */
  107.       END
  108. END /* end Select */
  109.  
  110. /* ---- Ask if tabs should be created. If so then, create tab stops. ---- */
  111. tabB4FirstCol = 0
  112. ShowMessage 1 0 '"Attempt to set up tab stops?" "" "" "Yes" "No" ""'
  113. IF ( RESULT = 1 ) THEN DO
  114.    tabPos = 0
  115.    DO c = firstCol TO lastCol
  116.       ADDRESS VALUE FDPort
  117.       GetColumnID POSITION c
  118.       GetColumnDef RESULT ALIGNMENT WIDTH
  119.       PARSE VAR RESULT calign cwidth
  120.  
  121.       SELECT
  122.          WHEN ( calign = "Left" ) THEN DO
  123.             inc = cwidth * 9
  124.             END
  125.          WHEN ( calign = "Right" ) THEN DO
  126.             tabpos = tabpos + (cwidth * 9)
  127.             inc = 0
  128.             END
  129.          WHEN ( calign = "Center") THEN DO
  130.             tabpos = tabpos + ((cwidth * 9) % 2)
  131.             inc = ((cwidth * 9) % 2)
  132.             END
  133.          OTHERWISE DO
  134.             END
  135.       END   /* end select */
  136.  
  137.       IF ( c = firstCol & calign ~= "Left" ) THEN
  138.          tabB4FirstCol = 1
  139.  
  140.       IF ( c ~= firstCol | tabB4FirstCol ) THEN DO
  141.          ADDRESS VALUE WPPort
  142.          SetMeasure Micropoints
  143.          SetTab tabpos calign
  144.       END
  145.  
  146.       tabpos = tabpos + inc + 45
  147.  
  148.    END   /* end column */
  149. END
  150.  
  151. /* ---- Ask if column names are wanted. If they are, then put them in. ---- */
  152. ADDRESS VALUE FDPort
  153. ShowMessage 1 0 '"Include column names?" "" "" "Yes" "No" ""'
  154. IF ( RESULT = 1 ) THEN DO
  155.    ADDRESS VALUE FDPort
  156.    data = ""
  157.    DO c = firstCol TO lastCol
  158.       IF ( c = firstCol & tabB4FirstCol ) THEN
  159.          data = data || D2C(9)
  160.  
  161.       GetColumnName POSITION c
  162.       data = data || RESULT
  163.       IF ( c ~= lastCol ) THEN
  164.          data = data || D2C(9)
  165.    END   /* end column */
  166.  
  167.    ADDRESS VALUE WPPort
  168.    Type data
  169.    NewParagraph
  170. END
  171.  
  172. /* ---- For each row of the database, collect the data in each column. ---- */
  173. /* ---- Then type the combined data for the row to the word processor. ---- */
  174. ADDRESS VALUE FDPort
  175. DO r = firstRow TO lastRow
  176.    data = ""
  177.  
  178.    ADDRESS VALUE FDPort
  179.    DO c = firstCol TO lastCol
  180.       IF ( c = firstCol & tabB4FirstCol ) THEN
  181.          data = data || D2C(9)
  182.  
  183.       CellData c r
  184.       data = data || RESULT
  185.       IF ( c ~= lastCol ) THEN
  186.          data = data || D2C(9)
  187.    END   /* end column */
  188.  
  189.    ADDRESS VALUE WPPort
  190.    Type data
  191.    IF ( r ~= lastRow ) THEN
  192.       NewParagraph
  193. END   /* end row */
  194.  
  195. ADDRESS VALUE FDPort
  196.  
  197. /* END OF MACRO FILE */