Wait for the file to be created with a timeout

I am trying to make prob vb6 wait for the creation of a PDF file. Right now I'm pausing in 3 seconds:

startTime = Time endTime = TimeValue(startTime) + TimeValue(TimeSerial(0,0,3)) While endTime > Time Wend If FSO.FileExists(sPdfFileName) Then OkCreatedPDF = True Else OkCreatedPDF = False End If 

but several times creating a PDF takes more than 3 seconds. Therefore, I would like to wait until the file is created, but with a timeout (says 10 seconds). I prefer not to extend the wait time, as this will be done a thousand times.

+5
source share
2 answers
 Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long) Function GeneratePDF() Dim sTimeout as Integer Call YourPDFroutine() StatusLabel.Caption = "Wait until PDF is finished..." While FSO.FileExists(sPdfFileName) = False sTimeout = sTimeout + 1 Sleep 1000 If sTimeOut > 10 Then OkCreatedPDF = False StatusLabel.Caption = "ERROR: Timeout!" Exit Function End If Wend OkCreatedPDF = True StatusLabel.Caption = "The PDF " & sPdfFileName & " was generated!" End Function 
+2
source

I don’t have VB6 env from me right now ... but whatever ... I made a few tweaks to your source code. If the API approach is not used, you can try the following:

 startTime = Time endTime = TimeValue(startTime) + TimeValue(TimeSerial(0,0,10)) While endTime > Time If FSO.FileExists(sPdfFileName) Then OkCreatedPDF = True Exit While Else OkCreatedPDF = False DoEvents() End If Wend 
0
source

All Articles