Try this...
Main Topics
Browse All TopicsI am looking to find a timer function that I can use to replace the sleep function in WSH for my HTA. I am using Internet Explorer to navigate a website and need to wait until the new page is in the Ready state.
Thanks for the help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You will want to avoid a tight loop that just checks for the elapsed time -- the CPU will peg 100% and no events can be processed.
I think the only usable option, other than the outside-the-box one that you described here:
http://www.Experts-Exchang
...is to not try to do the next step "inline." Instead, set a timer for the desired interval and exit the function. A little while later, the specified function resumes. Here's a general-purpose version of that. You pass it a function name and a duration in milliseconds. After that long, the specified function is executed.
Yes, this is awkward, but perhaps better than nothing. You will likely need to use global variable to maintain the state of your program.
In a common scenario, you will want to check a status every few seconds. In that case, your Step2() function checks the status and if good to go, moves on with the processing. If not ready, then call DelayThenDo() again (passing the "Step2()" fn again). And you might want to use code like TheNautican posted to record a "maximum delay" so that if the repeated status check contiinue to fail after, say 3 minutes, then you can stop doing them (the original sequence has, alas, failed).
After the coment above I tested my initial script and I see that there is a line out of sorts. If you use the code below, it will sit around till the page opens using about 10-20% CPU. Once the page is open, the CPU usage will drop to 0-1%.
The drawback here is mine has no cut off time as Dan mentioned above which might be a good idea if the page typically typically takes long to load or is unavailable.
rejoinder,
Putting a setInterval() call inside of the tight loop does not help. Note that the HTA is entriely unresponsive until the the action completes. You cannot drag or resize the window, let along click a button (e.g., a [Cancel Download] button).
Using the multi-step sequence that I suggeste, the HTA continues to function normally.
Dan, I like where you are going with your example. It is very similar to what I found on the Scripting Guys blog. What I am struggling with is how to manipulate the window that I opened with the "window.open" statement. Is there any way to check the ReadyState or status of the window? Or am I forced to wait a pre-defined amount of time and hope that the page has loaded succesfully?
bseiberling, if you launch a window with
Set objIE = CreateObject("InternetExpl
objIE.Visible = True
objIE.Navigate "http://experts-exchange.c
you can check the ReadyState and the Busy property of the window with
While objIE.ReadyState <> 4 And objIE.Busy = True
HTASleep 1
Wend
Regards,
Rob.
bseiberling,
>>how to manipulate the window that I opened...
you have an object of type window. http://msdn.microsoft.com/
As an HTA, you can do whatever you want with it. The way I handled this in an HTA was attached -- I haven't removed program-specific variables because I wanted to provide functional code. The desired status value is a member of document.
Note that I slapped a try ... catch around the status check because the document is not ready. It seems like a kludge, but it did work. The goScriptHelpers object is an ActiveX I wrote. It's not ready for publication :-)
My answer is best: http:#a25707097 It avoids shelling out to a DOS prompt. I also answered the follow-up (underlying) question with a complete example.
-- Dan
Business Accounts
Answer for Membership
by: TheNauticanPosted on 2009-10-30 at 14:10:50ID: 25706828
Ya, WScript isn't available for HTA since it uses MSHTA, so you have to use a Javascript function.
Here's a smple of how I call if from my VBscript in the HTA.
If strParam = "Restore" Then
objShell.SendKeys "{ENTER}"
jsSleep( 1000 )
objShell.SendKeys strAlias
jsSleep( 500 )
objShell.SendKeys "{TAB}{TAB}"
jsSleep( 500 )
objShell.SendKeys strLoc
jsSleep( 500 )
objShell.SendKeys "{TAB}{RIGHT}"
End If
Select allOpen in new window