home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / WordProcessors / slt-pgs3.lzx / PageStream3 / Scripts / MailMerge.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1996-10-20  |  3.9 KB  |  138 lines

  1. /* $VER: MailMerge.rexx 1.1 (10.05.96)
  2.    Copyright 1996 SoftLogik Publishing Corporation
  3.    May not be distributed without SoftLogik Publishing Corporation's express written permission */
  4.  
  5. /* Data Format
  6.  
  7. field1name»field2name»field3name...
  8. record1field1»record1field2»record1field3...
  9. record2field1»record2field2»record2field3...
  10. ...
  11.  
  12. where » is a tab
  13.  
  14. Data Example:
  15.  
  16. Address    City    Name    State    ZipCode
  17. 315 Consort Drive    St. Louis    Joe User    MO    63011
  18. 7178 Sonoma Way    Los Angeles    Helen Hudson    CA    95011
  19. 1234 Howe St.    Vancouver    Fred Stone    BC    V9N 5N1
  20.  
  21. */
  22.  
  23. OPTIONS RESULTS
  24. TRACE OFF
  25.  
  26. /* Make sure rexx support is opened */
  27. IF ~SHOW('L','rexxsupport.library') THEN
  28.    CALL ADDLIB('rexxsupport.library',0,-30)
  29.  
  30. ADDRESS 'PAGESTREAM'
  31.  
  32. /* OPEN THE DATA FILE */
  33. getfile title "'Select the ASCII data file'" LOAD POSBUTTON "OK" NEGBUTTON "Cancel"
  34. if rc~=0 then signal cleanup
  35. dfile=result
  36. call open(.ifile, dfile, 'R')
  37.  
  38. /* READ AND PARSE THE HEADER */
  39. dheader=readln(.ifile)
  40. fcount=1
  41. do forever
  42.     tpos=pos(d2c(9),dheader)
  43.     if tpos=0 then field.fcount=dheader
  44.         else field.fcount=left(dheader,tpos-1)
  45.     if tpos=0 then break
  46.     dheader=right(dheader,length(dheader)-tpos)
  47.     fcount=fcount+1
  48. end
  49.  
  50. /* SEE IF THE VARIABLES ALREADY EXIST */
  51. "setvariablevalue <nul>" variable field.1
  52. if rc~=0 then call createvar()
  53.  
  54. /* MAIL MERGE */
  55. /* ASK USER IF OK TO PRINT */
  56. allocarexxrequester '"Mail Merge"' 352 87
  57.     hDialog=result
  58. addarexxgadget hDialog EXIT 12 70 70 label "Print"
  59.     hDialog.ok=result
  60. addarexxgadget hDialog EXIT 270 70 70 label "Cancel"
  61.     hDialog.cancel=result
  62. addarexxgadget hDialog TEXT 8 10 344 border none string "'Enter the number of copies and then click'"
  63. addarexxgadget hDialog TEXT 8 22 344 border none string "'on Print to start printing.'"
  64. addarexxgadget hDialog STRING 12 42 122 label "C_opies" string '1'
  65.     hCopies=result
  66. doarexxrequester hDialog
  67.     action=result
  68. getarexxgadget hDialog hCopies string
  69.     copies=result
  70. freearexxrequester hDialog
  71. if action=hDialog.cancel then signal cleanup
  72.  
  73. do forever
  74.     /* READ THE RECORD */
  75.     dline=readln(.ifile)
  76.     if dline="" then break
  77.  
  78.     /* PARSE THE RECORD */
  79.     do i=1 to fcount
  80.         tpos=pos(d2c(9),dline)
  81.         if tpos=0 then line.i=dline
  82.             else line.i=left(dline,tpos-1)
  83.         if pos(d2c(39),line.i)>0 then line.i=d2c(34)||line.i||d2c(34) /* thanks Warren! */
  84.             else line.i=d2c(39)||line.i||d2c(39)
  85.         dline=right(dline,length(dline)-tpos)
  86.         if tpos=0 then break
  87.     end i
  88.  
  89.     /* UPDATE PGS3 VARIABLES */
  90.     'refresh off' /* Thanks Michael Tanzer! */
  91.     do i=1 to fcount
  92.         "setvariablevalue "line.i variable field.i
  93.     end i
  94.  
  95.     'refreshwindow'
  96.     'printdocument copies 'copies' page 1 sides both scale actual output grayscale printermarks off mirror off negative off'
  97. end
  98.  
  99. /* RESET VARIABLE NAMES */
  100. 'refresh on'
  101. do i=1 to fcount
  102.     "setvariablevalue <"field.i">" variable field.i
  103. end i
  104. 'refreshwindow'
  105.  
  106. call cleanup()
  107. EXIT
  108.  
  109. CREATEVAR:
  110.     do i=1 to fcount
  111.         'newvariable 'field.i' «'field.i'»'
  112.     end i
  113.     /* 'newvariable +Next «+»'
  114.         We'll use this when Find/Replace is done for a Next Record control
  115.         The script will search the text for these. If found, it will have to
  116.         replace following variable uses until the next Next control with
  117.         varname.1, etc. Then the script will have to reset multiple var groups
  118.         at once. */
  119.  
  120.     /* INFORM USER THAT VARS ARE CREATED */
  121.     allocarexxrequester '"Mail Merge"' 364 105
  122.         hDialog=result
  123.     addarexxgadget hDialog EXIT 282 88 70 label "OK"
  124.         hDialog.ok=result
  125.     addarexxgadget hDialog TEXT 8 10 356 border none string "'The mail merge variables have been created.'"
  126.     addarexxgadget hDialog TEXT 8 22 356 border none string "'Use the Type/Insert Variable » User String'"
  127.     addarexxgadget hDialog TEXT 8 34 356 border none string "'command to insert them into your document.'"
  128.     addarexxgadget hDialog TEXT 8 46 356 border none string "'When you are done, save it and then choose'"
  129.     addarexxgadget hDialog TEXT 8 58 356 border none string "'this macro again to print it.'"
  130.     doarexxrequester hDialog
  131.     freearexxrequester hDialog
  132.     signal cleanup
  133. RETURN
  134.  
  135. CLEANUP:
  136. call close(.ifile)
  137. EXIT
  138.