Help with Talk Code modification

I have some PP Talk code that has been working quite well in harvesting Invoice PDF’s from an archive folder. I would like to make a modification to the code to insert a “C” in front of the variable that it goes looking for when the code finds Credit Return in the position indicated (the # is correct, but in the archive folder the actual credit is preceded by a C. I am including the code here as it currently stands. I would love to attach the data stream that the code works on, but I am not allowed to upload a file!!. Thanks in advance for your help.

define(&Date,string,‘’)
define(&DBD,integer,0)
define(&Data_Date,string,‘’)

define(&x,integer,0)
define(&pdf,string,‘’)
define(&totalPages,integer,0)
define(&pagePDF,integer,0)

for(&x,15,1,54)
if((trim(@(&x,24,30)) = ‘INVOICE’) or(trim(@(&x,24,36)) = ‘CREDIT RETURN’))
&Data_Date := @(&x,14,15) + @(&x,17,18) + ‘20’ + @(&x,20,21)
% show(&Data_Date)
&DBD := @DaysBetweenDates(&Data_Date,&Watch.JobInfos[9],‘MMDDYYYY’)
% &DBD := @DaysBetweenDates(&Data_Date,‘08102013’,‘MMDDYYYY’)
% show(’ +’ + inttostr(&DBD))
if((&DBD < 365) and (&DBD >= 0))
% show(&Data_Date + ’ ’ + inttostr(&DBD))
% show(‘C:\archive\’ + trim(@(&x,2,10)) + ‘.pdf’)
crlf()
if(pdfpagecount(‘C:\archive\’ + trim(@(&x,2,10)) + ‘.pdf’)>0)

&pdf := ‘C:\archive\’ + trim(@(&x,2,10)) + ‘.pdf’
&totalPages := pdfpagecount(&pdf)

for(&pagePDF,1,1,&totalPages)
showpdf(&pdf,&pagePDF,8.4,10.6)
showpage()
endfor()
elseif
&PrintPage := true
$NoPDF
showpage
&PrintPage := false
endif()
endif()
endif()
endfor()

Hope I understood you need properly:

define(&Date,string,’’)
define(&DBD,integer,0)
define(&Data_Date,string,’’)

define(&x,integer,0)
define(&pdf,string,’’)
define(&totalPages,integer,0)
define(&pagePDF,integer,0)
define(&folder,string,‘’)

for(&x,15,1,54)
if((trim(@(&x,24,30)) = ‘INVOICE’) or (trim(@(&x,24,36)) = ‘CREDIT RETURN’))
if(trim(@(&x,24,36)) = ‘CREDIT RETURN’)
&folder := ‘C:\archive\C’
else
&folder := 'C:\archive'
endif()
&Data_Date := @(&x,14,15) + @(&x,17,18) + ‘20’ + @(&x,20,21)
% show(&Data_Date)
&DBD := @DaysBetweenDates(&Data_Date,&Watch.JobInfos[9],‘MMDDYYYY’)
% &DBD := @DaysBetweenDates(&Data_Date,‘08102013’,‘MMDDYYYY’)
% show(’ +’ + inttostr(&DBD))
if((&DBD < 365) and (&DBD >= 0))
% show(&Data_Date + ’ ’ + inttostr(&DBD))
% show(&folder + trim(@(&x,2,10)) + ‘.pdf’)
crlf()
if(pdfpagecount(&folder + trim(@(&x,2,10)) + ‘.pdf’)>0)

&pdf := &folder + trim(@(&x,2,10)) + ‘.pdf’
&totalPages := pdfpagecount(&pdf)

for(&pagePDF,1,1,&totalPages)
showpdf(&pdf,&pagePDF,8.4,10.6)
showpage()
endfor()
elseif
&PrintPage := true
$NoPDF
showpage
&PrintPage := false
endif()
endif()
endif()
endfor()

In bold what I have changed

Hamelj, thanks for your help. I am afraid i did not explain myself well enough. Here is the relevant section of the data stream:

INVOICE # DATE REMARKS
========== ======== ==============
1098174-0 10/5/2021 INVOICE
1111884-0 1/12/2022 CREDIT RETURN
1112482-1 1/12/2022 CREDIT RETURN
1119523-0 2/7/2022 CREDIT RETURN
C1112482-1 2/3/2022 PAYMENT

So, the TALK statement looks at the remarks section at position 24-30 and if it finds INVOICE and the date in the DATE column fits the range, it goes looking in the C:\Archive folder for the # at position 2-10 plus .PDF. That works perfectly. What I want to do is this:
If, at position 24-36 it finds CREDIT RETURN and the date checks properly (that I THINK I have correct), then append a C in front of the # at position 2-10 plus .PDF and look for that in the C:\Archive folder. So, in my example data stream above, instead of looking for 1111884-0.pdf in the C:\Archive folder for the first CREDIT RETURN, it would look for C111884-0.pdf and return that document.

So if CREDIT RETURN is found at position 24-36, you want to add a C in front of the number found at 2-10 of the same line to use as your PDF name.

Humm…unless I miss something, this is what my addition to your code does…no?
Explanation below of code added:

if(trim(@(&x,24,36)) = ‘CREDIT RETURN’) //Check for the CREDIT RETURN keyword
    &folder := 'C:\archive\C’           //Set the path to C:\archive\C
else
    &folder := 'C:\archive\’             //Set the path to C:\archive
endif()

further down the code

if(pdfpagecount(&folder + trim(@(&x,2,10)) + ‘.pdf’)>0) //Concatenate &folder with the data 
    &pdf := &folder + trim(@(&x,2,10)) + ‘.pdf’         //Same concatenation

Once concatenated you will get C:\archive\C1111884-0.PDF

I see where it could be confusing, in my code I wrote:

if(trim(@(&x,24,36)) = ‘CREDIT RETURN’)
&folder := 'C:\archive\C’
else
&folder := 'C:\archive’
endif()

where I should I’ve written:

if(trim(@(&x,24,36)) = ‘CREDIT RETURN’)
&folder := 'C:\archive\C’
else
&folder := 'C:\archive\’
endif()

:wink:

AHH, yes! I was looking at it as if you were addressing a different folder path! Now I see what you did! I will try it out and report back. Thank you very much.

I am getting an error.
Missing Quote in string variable"‘" with line "define(&Date,string,’') in object $internal TempObj
Object($InternalTempObj
)is empty. possible conversion error.

I see nothing wrong with the code and no missing Quotes. I have copied and pasted your code

@hamelj’s code wasn’t preformatted, so the quotes are screwed up when copy&pasting it.
Here is a (hopefully) properly formatted version that you should be able to copy&paste without problem. If there are any remaining issues, just make sure to replace any suspicious-looking quotes with the standard single quote:

define(&Date,string,'')
define(&DBD,integer,0)
define(&Data_Date,string,'')

define(&x,integer,0)
define(&pdf,string,'')
define(&totalPages,integer,0)
define(&pagePDF,integer,0)
define(&folder,string,'')

for(&x,15,1,54)
  if((trim(@(&x,24,30)) = 'INVOICE') or (trim(@(&x,24,36)) = 'CREDIT RETURN'))
    if(trim(@(&x,24,36)) = 'CREDIT RETURN')
      &folder := 'C:\archive\C'
    else
      &folder := 'C:\archive\'
    endif()
    &Data_Date := @(&x,14,15) + @(&x,17,18) + '20' + @(&x,20,21)
    % show(&Data_Date)
    &DBD := @DaysBetweenDates(&Data_Date,&Watch.JobInfos[9],'MMDDYYYY')
    % &DBD := @DaysBetweenDates(&Data_Date,'08102013','MMDDYYYY')
    % show(' +' + inttostr(&DBD))
    if((&DBD < 365) and (&DBD >= 0))
      % show(&Data_Date + ''+ inttostr(&DBD))
      % show(&folder + trim(@(&x,2,10)) + '.pdf')
      crlf()
      if(pdfpagecount(&folder + trim(@(&x,2,10)) + '.pdf')>0)

        &pdf := &folder + trim(@(&x,2,10)) + '.pdf'
        &totalPages := pdfpagecount(&pdf)

        for(&pagePDF,1,1,&totalPages)
          showpdf(&pdf,&pagePDF,8.4,10.6)
          showpage()
        endfor()
      elseif
        &PrintPage := true
        $NoPDF
        showpage
        &PrintPage := false
      endif()
    endif()
  endif()  
endfor()

Thanks Phil. One (hopefully) last question. Should the following lines actually us double backslashes like the original code?

&folder := 'C:\archive\C'
    else
      &folder := 'C:\archive\'

No. Contrary to JavaScript and some other languages, PlanetPress Talk does not require you to escape backslashes.

Thanks Phil and Hamilj. I appreciate your help. The code works perfectly! Phil, interesting on the escaped backslashes. Inserting them actually got me past an "unpaired quote"error that was still occuring.