I am using following code to prepare a record in pdf file. Sometimes this may be 100 pages or more. Since I use DOS command to copy, move and delete files, they are relatively slow and sbasic runs ahead of them and gives me error. I have placed @Loiter ( ) but it is arbitrary and you do not know how long wait is required for the subject record. I am concerned about getting error especially in the bigger file as 5 second loiter might not be enough for that, while 5 seconds might be plenty for other records. How can I make sure that irrespective of size of the record, I should not get the error because of slowing down because of DOS commands.
var vPrinter1 as String = "DocuCom PDF Driver"
var vPrinter2 as String = @GlobalValue ("ServerDefaultPrinter")
var vPath1 as String = "C:\PDFiles\"
var vPath2 as String = "C:\Assembly\"
var vPath3 as String = "C:\Sesame2\Records\"
var vPage1 as Int
var vSuccess as Int
var vRS as Int
var vLoop as Int
var vTotalRecords as Int
var vVisitDate as Date
var vName as String = First + " " + P_LastName
var vFiles as String
var vFilesWithPath as String
var vFinalFile as String
var n as Int
var vString1 as String
var vRSHandle as Int
var vDescription as String
var vFilename as String
var vExtFields as String = ""
var vNoOfRecords as Int
AlternateDefaultPrinter ("DocuCom PDF Driver")
vSuccess = @Shell ("Del " + vPath1 + "*.pdf" )
vSuccess = @Shell ("Del " + vPath2 + "*.pdf" )
vRS = @XResultSetSearch(@FN, "Physical", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + Chart) // Since Physical also have Chart element and Chart# never changes
if(vRS > -1)
{
//AlternateDefaultPrinter (vPrinter1)
vTotalRecords = @XResultSetTotal(vRS)
for vLoop = 1 to vTotalRecords
XResultSetCurrentPosition(vRS, vLoop)
vVisitDate = @XResultSetValue(vRS, "Date1")
vPage = 1
vStopReset = 0
Printing_Physical (vVisitDate)
next
XResultSetClose(vRS)
}
vFiles = @LocalListDirectory ("C:\PDFiles\")
If @CountStringArray (vFiles) > 1 then
{
vFiles = @SortStringArray (vFiles, 0)
For n = @CountStringArray (vFiles) downto 1
If vFilesWithPath = "" then
{
vFilesWithPath = @Chr (34) + vPath1 + @AccessStringArray (vFiles, n) + @chr (34)
}
Else
{
vFilesWithPath = vFilesWithPath + ";" + @Chr (34) + vPath1 + @AccessStringArray (vFiles, n) + @chr (34)
}
Next
vFilesWithPath = @Replace (vFilesWithPath, ";", " ")
//WriteLN (vFilesWithPath)
vFinalFile = vPath1 + vName + " " + @Month(@Date) + "-" + @DOM (@date) + "-" + @Year (@date) + "-visitnotes" + ".pdf"
//WriteLN (vFinalFile)
vSuccess = @Shell ( "PDFill.exe MERGE " + vFilesWithPath + " " + @chr (34) + vFinalFile + @chr (34) )
//vSuccess = @Shell ( "PDFill.exe MERGE " + @chr (34) + vFinalFile1 + @chr (34) + " " + @chr (34) + vFinalFile2 + @chr (34) + " " + @chr (34) + vFinalFile + @chr (34) )
//vSuccess = @AsynchShell (@Chr (34) + vFinalFile + @Chr (34)) //This code opens up the file
}
Else
{
//vFileName = vPath1 + vName + " " + @Month(@Date) + "-" + @DOM (@date) + "-" + @Year (@date)+ ".pdf"
//vSuccess = @AsynchShell (@Chr (34) + vPath1 + vFiles + @Chr (34))
}
vString1 = "CMD /C Move " + @Chr(34) + vFinalFile + @chr (34) + " " + vPath2 //If spcace is present it needs to be in quotes
//WriteLn (vString1)
CreateAProcess (vString1) //CreateAProcess requires cmd /c to open up Shell but does not require in @Shell command
//vSuccess = @Shell (vString5)
Loiter (5000) //Merging and Moving are taking time
//*********** Now Working with Documents File
//========= Following Routine Check the Documents file Exists on not and if does not give you choice to delete that record before merging them in pdf files
vRSHandle = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + Chart)
If vRSHandle > -1 then
{
xResultSetSort (vRSHandle, "DateAdded:1")
n = @XResultSetTotal (vRSHandle)
While n >= 1
{
xResultSetCurrentPosition (vRSHandle, n)
vDescription = @xResultSetValue (vRSHandle, "Description" )
//WriteLN (vDescription)
vFileName = @xResultSetValue (vRSHandle, "FileName" ) //Checking it again to make certain that no good record is deleted)
//WriteLN (vFileName)
If Not Fileexists (vFileName)
{
If @AskUser (vDescription + " file does not exist, Do you Want to Delet the Record?", "", "") then
{
xResultSetDeleteRecord (vRSHandle)
}
}
//WriteLN (@str (n))
n = n - 1
}
xResultSetClose (vRSHandle)
}
//******************************Convert RTF and PDF File *****************************************************************************************
vFinalFile = vPath1 + vName + " " + @Month (@date) + "-" + @DOM (@date) + "-" + @Year (@date) + "-Documents" + ".pdf"
//Loiter (5000)
vSuccess = @Shell ("Del " + vPath1 + "*.pdf" ) //Give Little time before a file is there to be moved
vRSHandle = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + Chart, "!Print=<>NO")
if(vRSHandle > -1)
{
vNoOfRecords = @XResultSetTotal(vRSHandle)
for vLoop = 1 to vNoOfRecords
XResultSetCurrentPosition(vRSHandle, vLoop)
vFileName = @XResultSetValue(vRSHandle, "FileName")
if @Right (vFileName, 3) = "rtf" then
{
//vSuccess = @Shell ( "c:\htmltools\htmltools.exe " + "-margin 30x30x30x30" + " " + vFileName + " " + @Replace (vFileName, "RTF", "PDF"))
//"C:\Program Files\docPrint Pro v5.0\doc2pdf.exe" -i c:\images\test.rtf -o c:\images\test.pdf
//vSuccess = @Shell ( @chr (34) + "C:\Program Files\docPrint Pro v5.0\doc2pdf.exe" + @Chr (34) + " -s ShowOfficeUI=1" + " -i " + vFileName + " -o " + @Replace (vFileName, "RTF", "PDF"))
//vFileName = @Replace (vFileName, "RTF", "PDF")
vSuccess = @Shell ( "RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " + @Chr (34) + vPrinter1 + @chr (34) )
MergeFilePrint(vFileName, "rtf", "", "", vExtFields, "", 0)
}
Else if @Right (vFileName, 3) = "pdf" then
{
vSuccess = @Shell ("Copy " + @Chr (34) + vFileName + @Chr (34) + " " + @Chr (34) + vPath1 + "Document" + @str (vLoop) + ".pdf" + @Chr (34) )
}
next
//WriteLn (vString)
XResultSetClose(vRSHandle)
}
vFiles = @LocalListDirectory ("C:\PDFiles\")
If @CountStringArray (vFiles) > 1 then
{
vFilesWithPath = "" //Reset the value of vFileWithPath
vFiles = @SortStringArray (vFiles, 0)
For n = @CountStringArray (vFiles) downto 1
If vFilesWithPath = "" then
{
vFilesWithPath = @Chr (34) + vPath1 + @AccessStringArray (vFiles, n) + @chr (34)
}
Else
{
vFilesWithPath = vFilesWithPath + ";" + @Chr (34) + vPath1 + @AccessStringArray (vFiles, n) + @chr (34)
}
Next
vFilesWithPath = @Replace (vFilesWithPath, ";", " ")
//WriteLN (vFilesWithPath)
//vFinalFile = vPath1 + vName + " " + @Month(@Date) + "-" + @DOM (@date) + "-" + @Year (@date) + "-visitnotes" + ".pdf"
//WriteLN (vFinalFile)
vSuccess = @Shell ( "PDFill.exe MERGE " + vFilesWithPath + " " + @chr (34) + vFinalFile + @chr (34) )
//vSuccess = @Shell ( "PDFill.exe MERGE " + @chr (34) + vFinalFile1 + @chr (34) + " " + @chr (34) + vFinalFile2 + @chr (34) + " " + @chr (34) + vFinalFile + @chr (34) )
//vSuccess = @AsynchShell (@Chr (34) + vFinalFile + @Chr (34)) //This code opens up the file
}
Else
{
//vFileName = vPath1 + vName + " " + @Month(@Date) + "-" + @DOM (@date) + "-" + @Year (@date)+ ".pdf"
//vSuccess = @AsynchShell (@Chr (34) + vPath1 + vFiles + @Chr (34)) //This is only if you want to open one page
}
vString1 = "CMD /C Move " + @Chr(34) + vFinalFile + @chr (34) + " " + vPath2 //If spcace is present it needs to be in quotes
//WriteLn (vString1)
CreateAProcess (vString1) //CreateAProcess requires cmd /c to open up Shell but does not require in @Shell command
//vSuccess = @Shell (vString1)
//==========================Now Combining file in Assembly folder and moving it to C:\Sesame2\Records\
Loiter (5000) //It seems like moving as well as merging above is taking time
vFinalFile = vPath3 + vName + " " + @Month (@date) + "-" + @DOM (@date) + "-" + @Year (@date) + ".pdf"
//WriteLN ("Final File = " + vFinalFile )
vFiles = @LocalListDirectory ("C:\Assembly\")
//WriteLN ("Files in Assembly Folder = " + vFiles)
If @CountStringArray (vFiles) > 1 then
{
vFilesWithPath = "" //Reset the value of vFileWithPath
vFiles = @SortStringArray (vFiles, 0)
For n = @CountStringArray (vFiles) downto 1
If vFilesWithPath = "" then
{
vFilesWithPath = @Chr (34) + vPath2 + @AccessStringArray (vFiles, n) + @chr (34)
}
Else
{
vFilesWithPath = vFilesWithPath + ";" + @Chr (34) + vPath2 + @AccessStringArray (vFiles, n) + @chr (34)
}
Next
vFilesWithPath = @Replace (vFilesWithPath, ";", " ")
//WriteLN ("Files From Assembley = " + vFilesWithPath)
//vFinalFile = vPath1 + vName + " " + @Month(@Date) + "-" + @DOM (@date) + "-" + @Year (@date) + "-visitnotes" + ".pdf"
//WriteLN ("Final File = " + vFinalFile)
vSuccess = @Shell ( "PDFill.exe MERGE " + vFilesWithPath + " " + @chr (34) + vFinalFile + @chr (34) )
//vSuccess = @Shell ( "PDFill.exe MERGE " + @chr (34) + vFinalFile1 + @chr (34) + " " + @chr (34) + vFinalFile2 + @chr (34) + " " + @chr (34) + vFinalFile + @chr (34) )
vSuccess = @AsynchShell (@Chr (34) + vFinalFile + @Chr (34)) //This code opens up the file
}
Else
{
//vFileName = vPath1 + vName + " " + @Month(@Date) + "-" + @DOM (@date) + "-" + @Year (@date)+ ".pdf"
vSuccess = @AsynchShell (@Chr (34) + vFilesWithPath + @Chr (34)) //This is only if you want to open one page
}
vSuccess = @Shell ( "RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n " + @Chr (34) + vPrinter2 + @chr (34) )// Default Printer in place again