我正在尝试制作一个 vb6 prog 以等待创建 pdf 文件。
现在我只是像这样暂停 3 秒:
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
但有时 pdf 创建需要超过 3 秒。所以我想等待创建文件但超时(比如 10 秒)。我不想延长等待时间,因为这将运行一千次。
最佳答案
您可以使用 Sleep
1000 毫秒,这意味着它将等待 1 秒,直到它继续运行代码,使用名为 sTimeout
的标志变量您可以定义运行循环的秒数,我硬编码为 10,但您可以创建另一个变量来设置秒数,每秒它将运行循环并增加 sTimeout
一,一旦达到 10 它将完成 while
环形。
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
关于vb6 - 等待文件创建超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32432797/