home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / Database / FinalData3.DMS / FinalData3.adf / FDMacros / FDListMerge < prev    next >
Encoding:
Text File  |  1995-09-25  |  7.9 KB  |  242 lines

  1. /* ============================================================================= */
  2. /* Final Data ARexx Macro.                                                       */
  3. /* FDListMerge - Perform a list merge to a FinalWriter or FinalCopy_II document. */
  4. /* $VER: FDListMerge 1.3 (25.09.95)                                               */
  5. /* © 1995 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. /* Changes:                                                                      */
  32. /*  V1.1   Initial version for Final Data.                                       */
  33. /*  V1.2   Modified for Final Data R2 to support non-contiguous row and column   */
  34. /*         selection.                                                            */
  35. /*  V1.3   Modified for Final Data R3 to support hidden columns.                 */
  36. /* ============================================================================= */
  37. OPTIONS RESULTS
  38.  
  39. /* ---- Load the rexxsupport library ---- */
  40. IF ( ADDLIB("rexxsupport.library", 0, -30, 0) = FALSE) THEN EXIT 20
  41.  
  42. /* ---- Get the address of the port we were called from. ---- */
  43. FDPort = ADDRESS()
  44.  
  45. /* ---- Find the address of the word processing port. ------------------- */
  46. /* ---- This will use the first port it can find with the base name. ---- */
  47. /* ---- First try to get a FinalWriter port. If we can't find one, ------ */
  48. /* ---- then try to get a FinalCopy port. ------------------------------- */
  49. WPPortBase = "FINALW."
  50. found = 0
  51. DO p = 1 TO 50
  52.    IF ( SHOWLIST('P', WPPortBase || p) ) THEN DO
  53.       WPPort = WPPortBase || p
  54.       found = 1
  55.       LEAVE
  56.    END
  57. END
  58.  
  59. /* ---- Try FinalCopy port ---- */
  60. IF ( ~ found ) THEN DO
  61.    WPPortBase = "FINALC."
  62.    found = 0
  63.    DO p = 1 TO 50
  64.       IF ( SHOWLIST('P', WPPortBase || p) ) THEN DO
  65.          WPPort = WPPortBase || p
  66.          found = 1
  67.          LEAVE
  68.       END
  69.    END
  70. END
  71.  
  72. IF ( ~ found ) THEN DO
  73.    ShowMessage 1 1 '"Can not find word processing port!" "" "" "OK" "" ""'
  74.    EXIT 10
  75. END
  76.  
  77. DROP p
  78. DROP found
  79.  
  80. /* ---- Determine the number of columns and rows in the database. ---- */
  81. NumRows
  82. nrows = RESULT
  83. NumColumns
  84. ncols = RESULT
  85. IF ( nrows = 0 ) THEN DO
  86.    ShowMessage 1 1 '"No rows of data in database!" "" "" "OK" "" ""'
  87.    EXIT 10
  88. END
  89.  
  90. IF ( ncols = 0 ) THEN DO
  91.    ShowMessage 1 1 '"No columns defined in database!" "" "" "OK" "" ""'
  92.    EXIT 10
  93. END
  94.  
  95. /* ---- Determine which rows and columns will get transferred. ----------- */
  96. /* ---- If selection is OFF or CELL then use all the columns and rows ---- */
  97. firstRow = 1
  98. firstCol = 1
  99. lastRow = nrows
  100. lastCol = ncols
  101.  
  102. DO c = firstCol TO lastCol
  103.    useCol.c = 1;
  104. END
  105.  
  106. DO r = firstRow TO lastRow
  107.    useRow.r = 1;
  108. END
  109.  
  110. SelectionInfo
  111. PARSE VAR RESULT selType selFrom selTo
  112. SELECT
  113.    WHEN ( selType = "COLUMNS" ) THEN DO
  114.       firstCol = selFrom
  115.       lastCol = selTo
  116.  
  117.         DO c = firstCol TO lastCol
  118.             IsColumnSelected c
  119.             useCol.c = RESULT
  120.         END
  121.    END
  122.  
  123.    WHEN ( selType = "ROWS" ) THEN DO
  124.       firstRow = selFrom
  125.       lastRow = selTo
  126.  
  127.         DO r = firstRow TO lastRow
  128.             IsRowSelected r
  129.             useRow.r = RESULT
  130.         END
  131.  
  132.         DO c = firstCol TO lastCol
  133.          GetColumnID POSITION c
  134.          cid = RESULT
  135.          IsColumnHidden COlUMNID cid
  136.             IF    ( RESULT ) THEN
  137.                 useCol.c = 0
  138.         END
  139.    END
  140.  
  141.    OTHERWISE DO   /* OFF or CELL */
  142.    END
  143. END /* end Select */
  144.  
  145.  
  146.  
  147. /* ---- Ask if tabs should be created. If so then, create tab stops. ---- */
  148. tabB4FirstCol = 0
  149. ShowMessage 1 0 '"Attempt to set up tab stops?" "" "" "Yes" "No" ""'
  150. IF ( RESULT = 1 ) THEN DO
  151.    tabPos = 0
  152.    DO c = firstCol TO lastCol
  153.         IF ( useCol.c ) THEN DO
  154.             ADDRESS VALUE FDPort
  155.          GetColumnID POSITION c
  156.          GetColumnDef RESULT ALIGNMENT WIDTH
  157.          PARSE VAR RESULT calign cwidth
  158.  
  159.          SELECT
  160.             WHEN ( calign = "Left" ) THEN DO
  161.                inc = cwidth * 9
  162.                END
  163.             WHEN ( calign = "Right" ) THEN DO
  164.                tabpos = tabpos + (cwidth * 9)
  165.                inc = 0
  166.                END
  167.             WHEN ( calign = "Center") THEN DO
  168.                tabpos = tabpos + ((cwidth * 9) % 2)
  169.                inc = ((cwidth * 9) % 2)
  170.                END
  171.             OTHERWISE DO
  172.                END
  173.          END   /* end select */
  174.  
  175.          IF ( c = firstCol & calign ~= "Left" ) THEN
  176.             tabB4FirstCol = 1
  177.  
  178.          IF ( c ~= firstCol | tabB4FirstCol ) THEN DO
  179.             ADDRESS VALUE WPPort
  180.             SetMeasure Micropoints
  181.             SetTab tabpos calign
  182.          END
  183.  
  184.          tabpos = tabpos + inc + 45
  185.       END /* end if useCol */
  186.  
  187.    END   /* end column loop */
  188. END
  189.  
  190. /* ---- Ask if column names are wanted. If they are, then put them in. ---- */
  191. ADDRESS VALUE FDPort
  192. ShowMessage 1 0 '"Include column names?" "" "" "Yes" "No" ""'
  193. IF ( RESULT = 1 ) THEN DO
  194.    ADDRESS VALUE FDPort
  195.    data = ""
  196.    DO c = firstCol TO lastCol
  197.         IF    ( useCol.c ) THEN DO
  198.          IF ( c = firstCol & tabB4FirstCol ) THEN
  199.             data = data || D2C(9)
  200.  
  201.          GetColumnName POSITION c
  202.          data = data || RESULT
  203.          IF ( c ~= lastCol ) THEN
  204.             data = data || D2C(9)
  205.       END /* end if usecol */
  206.    END   /* end column */
  207.  
  208.    ADDRESS VALUE WPPort
  209.    Type data
  210.    NewParagraph
  211. END
  212.  
  213. /* ---- For each row of the database, collect the data in each column. ---- */
  214. /* ---- Then type the combined data for the row to the word processor. ---- */
  215. ADDRESS VALUE FDPort
  216. DO r = firstRow TO lastRow
  217.     IF ( useRow.r ) THEN DO
  218.       data = ""
  219.  
  220.       ADDRESS VALUE FDPort
  221.       DO c = firstCol TO lastCol
  222.            IF ( useCol.c ) THEN DO
  223.             IF ( c = firstCol & tabB4FirstCol ) THEN
  224.                data = data || D2C(9)
  225.  
  226.             CellData c r
  227.             data = data || RESULT
  228.             IF ( c ~= lastCol ) THEN
  229.                data = data || D2C(9)
  230.          END /* end if usecol */
  231.       END   /* end column */
  232.  
  233.       ADDRESS VALUE WPPort
  234.       Type data
  235.       IF ( r ~= lastRow ) THEN
  236.          NewParagraph
  237.    END /* end userow */
  238. END   /* end row */
  239.  
  240. ADDRESS VALUE FDPort
  241.  
  242. /* END OF MACRO FILE */