The "//Test If Files Exist" portion of the script works but randomly. I can run the script and all of the routines properly execute, files are saved in the proper locations but on completion the message box and log MAY indicate a file or 2 is missing. A second run, MIGHT complete properly or not.
The "//Test & Run VWR Scrapes" portion of the script NEVER fails, i.e., the test is always accurate as to the file having been created of not. If the file exists then that portion of the script does not execute, if the file does not exist then it does.
I suspect the problem is in the script, I just can't see where.
Any useful suggestions will be gratefully received.
//Variables
Let>loopcounter=-1
GetDate>vToday
Let>Missing1=FAILED On Loop 0 - Retry:%CRLF%
Let>Missing2=Files Missing:%CRLF%
Let>Path=Z:\VWR
Let>RuntimeHr=0.03
Let>RunTimeMin=RunTimeHr*60
Let>RunTimeSec=RunTimeMin*60
Let>LoopMax=1
Let>LoopTill=LoopMax+1
Let>LogFileLines=-100
Let>SizeLogFile=50000
Let>LogFile=%Path%\Log\VWR.Log
/*=============================================*/
//Delete VWR Output Files
DeleteFile>%Path%\Output\R*.*
DeleteFile>%Path%\Output\Y*.*
DeleteFile>%Path%\Output\Interactive*.*
Wait>10
//Trim VWR Log File to Last "n" Lines - Note: Tail.exe is saved in "C:\Windows\addins\" Directory
FileSize>%Path%\Log\VWR.Log,LogFileSize
If>LogFileSize>%SizeLogFile%
Let>RP_WAIT=1
Run>cmd.exe /c C:\Windows\addins\tail.exe %LogFileLines% "%Path%\Log\VWR.Log">"%Path%\Log\VWR TEMP.Log"
DeleteFile>%Path%\Log\VWR.Log
RenameFile>%Path%\Log\VWR TEMP.Log,%Path%\Log\VWR.Log
Let>RP_WAIT=0
endif
Repeat>loopcounter
//Close Message Window
IfWindowOpen>Macro Scheduler Message
CloseWindow>Macro Scheduler Message
endif>
//Test If Files Exist
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv,,Skip
IfFileExists>%Path%\Output\R_Estimates_b\R_Estimates_b_data_1.csv,,Skip
IfFileExists>%Path%\Output\R_Estimates_c\R_Estimates_c_data_1.csv,,Skip
//Log and Exit Script If ALL Files Exist After "0" Try
if>loopcounter=0
Timestamp>LogFile,%vToday%, COMPLETED With No Errors - Yippie!!! %CRLF%
Exit>0
endif
//Log and Exit Script If ALL Files Exist After 1st -> "LoopMax" Retry
if>loopcounter>0
Timestamp>LogFile,%vToday%, COMPLETED With Errors!!! - Succeeded On Loop #%loopcounter% %CRLF%%Missing1%
Exit>0
endif
//Log and Exit Script If File(s) FAILED After "LoopMax" Retry
Label>Skip
if>loopcounter=LoopMax
Timestamp>LogFile,%vToday%, FAILED After %LoopMax% Retries!!! %CRLF%%Missing2%
MessageModal>FAILED After %LoopMax% Retries!!! %CRLF%%Missing2%
Exit>0
endif
Let>loopcounter=loopcounter+1
Let>Runcounter=loopcounter+1
//Time Calculation & Screen MessageBox - All Attempts
VBEval>DateAdd("s", %RunTimeSec%, now),LoopEndTime
Let>MSG_STAYONTOP=1
Message>Loop Run Time: %RunTimeHr% Hour(s) / %RunTimeMin% Min(s) %CRLF%Loop Completion: %LoopEndTime% %CRLF%Attempt No.: %Runcounter% of %LoopTill%
//Test & Run VWR Scrapes
IfFileExists>%Path%\Output\R_Estimates_a\R_Estimates_a_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates a.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates a %CRLF%
endif>
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates a %CRLF%
endif
endif
IfFileExists>%Path%\Output\R_Estimates_b\R_Estimates_b_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates b.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates b %CRLF%
endif
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates b %CRLF%
endif
endif
IfFileExists>%Path%\Output\R_Estimates_c\R_Estimates_c_data_1.csv
//Do nothing
else
run>"C:\Program Files\VWR\RunProject.exe" "%Path%\Projects\R Estimates c.rip"
if>loopcounter>0
Let>Missing1=%Missing1%(%loopcounter%)R Estimates c %CRLF%
endif>
if>loopcounter=LoopMax
Let>Missing2=%Missing2%- R Estimates c %CRLF%
endif
endif
//Pause Loop RunTimeSec
//"Kill" RunProject.exe
VBSTART
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process where name = 'RunProject.exe'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
VBEND
//Loop Script "n" Times
Until>loopcounter=LoopTill