home *** CD-ROM | disk | FTP | other *** search
- /* $VER: MailMerge.rexx 1.1 (10.05.96)
- Copyright 1996 SoftLogik Publishing Corporation
- May not be distributed without SoftLogik Publishing Corporation's express written permission */
-
- /* Data Format
-
- field1name»field2name»field3name...
- record1field1»record1field2»record1field3...
- record2field1»record2field2»record2field3...
- ...
-
- where » is a tab
-
- Data Example:
-
- Address City Name State ZipCode
- 315 Consort Drive St. Louis Joe User MO 63011
- 7178 Sonoma Way Los Angeles Helen Hudson CA 95011
- 1234 Howe St. Vancouver Fred Stone BC V9N 5N1
-
- */
-
- OPTIONS RESULTS
- TRACE OFF
-
- /* Make sure rexx support is opened */
- IF ~SHOW('L','rexxsupport.library') THEN
- CALL ADDLIB('rexxsupport.library',0,-30)
-
- ADDRESS 'PAGESTREAM'
-
- /* OPEN THE DATA FILE */
- getfile title "'Select the ASCII data file'" LOAD POSBUTTON "OK" NEGBUTTON "Cancel"
- if rc~=0 then signal cleanup
- dfile=result
- call open(.ifile, dfile, 'R')
-
- /* READ AND PARSE THE HEADER */
- dheader=readln(.ifile)
- fcount=1
- do forever
- tpos=pos(d2c(9),dheader)
- if tpos=0 then field.fcount=dheader
- else field.fcount=left(dheader,tpos-1)
- if tpos=0 then break
- dheader=right(dheader,length(dheader)-tpos)
- fcount=fcount+1
- end
-
- /* SEE IF THE VARIABLES ALREADY EXIST */
- "setvariablevalue <nul>" variable field.1
- if rc~=0 then call createvar()
-
- /* MAIL MERGE */
- /* ASK USER IF OK TO PRINT */
- allocarexxrequester '"Mail Merge"' 352 87
- hDialog=result
- addarexxgadget hDialog EXIT 12 70 70 label "Print"
- hDialog.ok=result
- addarexxgadget hDialog EXIT 270 70 70 label "Cancel"
- hDialog.cancel=result
- addarexxgadget hDialog TEXT 8 10 344 border none string "'Enter the number of copies and then click'"
- addarexxgadget hDialog TEXT 8 22 344 border none string "'on Print to start printing.'"
- addarexxgadget hDialog STRING 12 42 122 label "C_opies" string '1'
- hCopies=result
- doarexxrequester hDialog
- action=result
- getarexxgadget hDialog hCopies string
- copies=result
- freearexxrequester hDialog
- if action=hDialog.cancel then signal cleanup
-
- do forever
- /* READ THE RECORD */
- dline=readln(.ifile)
- if dline="" then break
-
- /* PARSE THE RECORD */
- do i=1 to fcount
- tpos=pos(d2c(9),dline)
- if tpos=0 then line.i=dline
- else line.i=left(dline,tpos-1)
- if pos(d2c(39),line.i)>0 then line.i=d2c(34)||line.i||d2c(34) /* thanks Warren! */
- else line.i=d2c(39)||line.i||d2c(39)
- dline=right(dline,length(dline)-tpos)
- if tpos=0 then break
- end i
-
- /* UPDATE PGS3 VARIABLES */
- 'refresh off' /* Thanks Michael Tanzer! */
- do i=1 to fcount
- "setvariablevalue "line.i variable field.i
- end i
-
- 'refreshwindow'
- 'printdocument copies 'copies' page 1 sides both scale actual output grayscale printermarks off mirror off negative off'
- end
-
- /* RESET VARIABLE NAMES */
- 'refresh on'
- do i=1 to fcount
- "setvariablevalue <"field.i">" variable field.i
- end i
- 'refreshwindow'
-
- call cleanup()
- EXIT
-
- CREATEVAR:
- do i=1 to fcount
- 'newvariable 'field.i' «'field.i'»'
- end i
- /* 'newvariable +Next «+»'
- We'll use this when Find/Replace is done for a Next Record control
- The script will search the text for these. If found, it will have to
- replace following variable uses until the next Next control with
- varname.1, etc. Then the script will have to reset multiple var groups
- at once. */
-
- /* INFORM USER THAT VARS ARE CREATED */
- allocarexxrequester '"Mail Merge"' 364 105
- hDialog=result
- addarexxgadget hDialog EXIT 282 88 70 label "OK"
- hDialog.ok=result
- addarexxgadget hDialog TEXT 8 10 356 border none string "'The mail merge variables have been created.'"
- addarexxgadget hDialog TEXT 8 22 356 border none string "'Use the Type/Insert Variable » User String'"
- addarexxgadget hDialog TEXT 8 34 356 border none string "'command to insert them into your document.'"
- addarexxgadget hDialog TEXT 8 46 356 border none string "'When you are done, save it and then choose'"
- addarexxgadget hDialog TEXT 8 58 356 border none string "'this macro again to print it.'"
- doarexxrequester hDialog
- freearexxrequester hDialog
- signal cleanup
- RETURN
-
- CLEANUP:
- call close(.ifile)
- EXIT
-