How can I wait for 10 seconds

dorisr

Programmer Analyst
Local time
Today, 05:19
Joined
May 5, 2008
Messages
15
Hi All,

I'm looking for a way to make a wait in my code before executing next steps in my procedure...

I will explain what I'm doing :
On button clic, I have set a vbscript to make a comma delimited file from a text report. And after that the vbscript has been executed in msaccess, my code do an import of the newfile in a pre-define table. But the script takes about 5 seconds to do.... and I need to wait about 10 seconds after the execution of the script...

Can anyone help me on this ?

Thanks,
Doris
 
Two ways to do it:

Code:
DoEvents

or use an API to call sleep 10000 (milliseconds):

Code:
Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
 
Why do an external VBScript at all??
 
what you REALLY need is to shell the command, and wait for it to signal that its finished

sort of shell and wait

I got a utility called execcmd form here, I think, but im not exactly sure where - it uses this api call

Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds _
As Long) As Long

it returns a code when its done to indicate success
 
Thanks for your advice I'm working on it.
A do event will do the trick.

Doris
 
doevents wont do it

if you have code something like

shell ("a programme")
doevents
msgbox("Next Step")

the msgbox will open immediately

what you need is

shellANDwait ("a programme")
msgbox("Next Step")

with additional code that makes sure the msgbox statement isnt processed UNTIL the shellandwait dignals it has completed
 
Hi, if you insert this in a module and just use the command Pause(xx) wherever you like in your project that should work for you - xx is equal to the number of seconds:


Public Function Pause(NumberOfSeconds As Variant)
On Error GoTo Err_Pause

Dim PauseTime As Variant, Start As Variant

PauseTime = NumberOfSeconds
Start = Timer
Do While Timer < Start + PauseTime
DoEvents
Loop

Exit_Pause:
Exit Function

Err_Pause:
MsgBox Err.Number & " - " & Err.Description
Resume Exit_Pause

End Function


HTH
 
With a slight modification to the module from the "Shell and Wait example" AppsPro.com I believe this will work perfectly for you. It keeps track of the processes running and knows when it has been completed.

The line that has to change is :
Code:
If Not bShellAndWait("Calc.exe", vbNormalFocus) Then Err.Raise 9999
to:
Code:
If Not bShellAndWait("cmd /c " & chr(34) &  _
YourVBSPathandFilename & chr(34), vbNormalFocus) Then Err.Raise 9999
Note:
The chr function must be in there as the shell function is opening a command prompt and inserting your file name. Something about how cmd doesn't like spaces or some thing, I dunno. :D

Also; because it's opening a cmd window, it's possible to have multiple VBS files run via a batch file, which forces each VBS to run sequentially.

Note: It doesn't look for the VBS but only the overall cmd.
 

Attachments

Users who are viewing this thread

Back
Top Bottom