Normal Topic Error in Example Merge Code . . . (Read 667 times)
Brett_Australia
Member
*
Offline


Having a nice nap under
a tree sounds good to
me

Posts: 2
Location: Brisbane - Australia
Joined: Mar 5th, 2004
Error in Example Merge Code . . .
May 14th, 2004 at 10:18am
Print Post Print Post  
Help!

The following example code (supllied with Sesame) does not now work with V1.0.3.  I have not altered the example code since the original work on V1.0.0.

Using the same code, now I am able to choose ONLY the first option in the list.  If I choose any other option (stored in Documents.txt file) I get an error message stating that the file does not exist.

Original Code as supplied . . .

var vFileHandle as Int          // For writing data file
var vHeader as String           // Data file header line
var vData as String             // Data file data line
var n as Int = 1            // General purpose counter
var vSelectedDoc as String      // Document selected from menu
var vOneOrAll as String         // Include record(s) option
var F as array[25] of String    // Mergeable fields array
var vStartingRec = @ResultSetCurrentPosition()
var vGoPrint as String

/* This program differs slightly from the one in
   Appendix 2 of the Sesame Programming Guide.
   This one gets its listFirst of available merge documents
   from an external text file (list.txt) instead of the
   document names being hard-coded into the program.
   One may then create any number of merge documents,
   and simply edit the list.txt file (with Notepad) to
   correspond to the available merge documents */

// Next 4 lines user modifiable
var vDataPath as String = "c:\SESAME\DATA\docs\Merge.txt"
var vDocsPath as String = "c:\SESAME\DATA\docs\"
var vWordPath as String = "c:\SESAME\DATA\Publisher.bat"
var vListPath as String = "c:\SESAME\DATA\docs\Documents.txt"

SUBROUTINE PrintCurrentRecordOnly()

If @Askuser("Merge print the " + vSelectedDoc + " for "
+ vOneOrAll + "?","","") Then
{

vGoPrint = "Yes"

n = 1                  
While F[n] <> ""
{
     vHeader = vHeader + F[n]   + "^"
     vData   = vData   + @(F[n]) + "^"
     n = n + 1
}

vFileHandle = fileOpen(vDataPath)
fileSeek(vFileHandle, 0)
fileWriteLn(vFileHandle, vHeader + @NewLine() + vData)
fileClose(vFileHandle)

}

END SUBROUTINE

SUBROUTINE PrintAllRetrievedRecords()

var n as Int
var i as Int = 1

If @Askuser("Merge Print " + vSelectedDoc + " for these " + @ResultSetTotal() + " retrieved records?",
"( If not, cancel this task, press F7 for a new search,"," and retrieve the records DO you want to print. )")
Then
{

     vGoPrint = "Yes"

     n = 1                  
     While F[n] <> ""
           {
           vHeader = vHeader + F[n]   + "^"
           n = n + 1
           }

     vFileHandle = fileOpen(vDataPath)
     fileSeek(vFileHandle, 0)
     fileWriteLn(vFileHandle, vHeader)

     For n = 1 to @ResultSetTotal()

     ResultSetCurrentPosition(n)

     While F[i] <> ""
           {
           vData = vData + @(F[i]) + "^"
           i = i + 1
           }

     FileWriteLn(vFileHandle, vData)

     @Msg("Processed Record " + n + " of " + @ResultSetTotal())
     vData = ""
     i = 1

     Next

     fileClose(vFileHandle)

     // Rewind to record where it all started
     ResultSetCurrentPosition(vStartingRec)

     }

END SUBROUTINE


// BEGIN MAIN PROGRAM

// Build documents menu

vSelectedDoc = @PopupMenu(
@insert(vListPath), "SELECT MERGE DOCUMENT" )

// Build which record(s) menu

vOneOrAll = @PopupMenu(
"THIS Record Only;" +
"ALL Retrieved Records;" , "SELECT RECORD(S) TO MERGE PRINT" )

If vSelectedDoc <> "" and vOneOrAll <> "" Then
{      

     // Delete exsting data file. New one will be generated.
     If FileExists(vDocsPath + vSelectedDoc) Then
     {
     fileDelete(vDataPath)      

     // Fields available for merging
     F[1] = "SSN";         
     F[2] = "SCN";    
     F[3] = "PRODUCT"
     F[4] = "PRODUCTVERSIONNUMBER";
     F[5] = "PURCHASED"
     F[6] = "PURCHASEDFROM"      
     F[7] = "SUPPORTTYPE";    
     F[8] = "SUPPORTDESCRIPTION"
     F[9] = "SUPPORTFROMTEXT"
     F[10] = "SUPPORTEXPIRESTEXT";
     F[11] = "COMPANYNAME";
     F[12] = "TRADINGAS";
       F[13] = "TITLE";
     F[14] = "FIRSTNAME";
     F[15] = "LASTNAME" ;
     F[16] = "CONTACTNAME";       
     F[17] = "PADDRESS";
     F[18] = "PADDRESS2";
     F[19] = "PADDRESSTSP";
     F[20] = "EMAIL";
     F[21] = "PHONEBH";
     F[22] = "PHONEFAX"
     F[23] = "PHONEMOBILE";
     F[24] = "PHONEAH"

     If vOneOrAll = "THIS Record Only" Then
           PrintCurrentRecordOnly()
     Else
           PrintAllRetrievedRecords()

     If vGoPrint = "Yes" Then
     {
           // Start Word via Word.bat and pass doc filename.            
           n = @Shell(vWordPath + " " + @Chr(34) + vDocsPath + vselectedDoc + @Chr(34))
           If n = 1 Then
           @MSgbox(vDocsPath + vSelectedDoc,"word.bat not found or something else wrong.","")
     }
     }
     Else
           @Msgbox(vDocsPath + vSelectedDoc + " doesn't exist.","","Aw shucks!")
}


Documents.txt file contents . . .

DL Envelope.pub ;
V11.00 Upgrade Order Form MERGE FIELDS ONLY.pub ;
Order Form EASC Special Offer March 2004.pub ;

Thnaks in advance  Smiley
  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Error in Example Merge Code . . .
Reply #1 - May 14th, 2004 at 10:34am
Print Post Print Post  
Are the items in your Documents.txt file separated by commas or semicolons?
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Brett_Australia
Member
*
Offline


Having a nice nap under
a tree sounds good to
me

Posts: 2
Location: Brisbane - Australia
Joined: Mar 5th, 2004
Re: Error in Example Merge Code . . .
Reply #2 - May 15th, 2004 at 9:51am
Print Post Print Post  
Quote:
Are the items in your Documents.txt file separated by commas or semicolons?


semicolon as shown previously . . .

Documents.txt file contents . . .

DL Envelope.pub ; <<<<------------------------- semicolon
V11.00 Upgrade Order Form MERGE FIELDS ONLY.pub ;
Order Form EASC Special Offer March 2004.pub ;



  
Back to top
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Error in Example Merge Code . . .
Reply #3 - May 15th, 2004 at 12:48pm
Print Post Print Post  
Sorry, I didn't see that part at the bottom. I was asking because we made a change to @PopupMenu to only accept semicolon as a separator.

The sample you are working with is not one of the Lantica samples. It is a separate application developed independently by Tom Marcellus. I don't really know much about it.

You may want to confirm that the files actually are where you think they are. You may also to want to try using some filenames that are less long and complex, as a test case. You may need to add the Chr(34)'s into where the FileExists function is called.

Also, try reordering the file and see if the issue is that you can only select the first doc, or if you can only select that one particular doc, regardless of where it appears.

If you can't determine what the problem is, I suggest you contact Tom directly for support on this application.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged