Since Sleep is a WScript method it's not available,
but you can do the following:
Put a file named sleeper.vbs in the same folder
with the HTA. Add this code to it:
Dim Arg
on error resume next
Arg = WScript.Arguments(0)
wscript.sleep Arg
------------------
Then put a sub in your HTA script block like so:
Sub Sleep(MSecs)
Dim Ret
On Error Resume Next
Ret = SH.Run("sleeper.vbs " & MSecs, , True)
If (Ret <> 0) Then
MsgBox "Possible problem with Sleep Function. Make sure
sleeper.vbs is in utility folder.", 64, "MSI Utility"
End If
End Sub
--------------------
You can then just call the sub:
Sleep 5 '-- pause 5 seconds.
-----------------
There's no DoEvents in VBScript.
<html>
<head>
<title>Hello</title>
<HTA:APPLICATION
ID="objHello"
APPLICATIONNAME="Hello"
SCROLL="auto"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT LANGUAGE="VBScript">
dim TimerID
Sub Window_OnLoad
self.ResizeTo 200,100
sleep = 10
msgbox "click to start 5 second timer"
TimerID = window.setInterval("PartTwo",5000)
End Sub
Sub PartTwo
window.ClearInterval(TimerID)
msgbox "continuing with Part Two"
TimerID = window.setInterval("PartThree",5000)
End Sub
Sub PartThree
window.ClearInterval(TimerID)
msgbox "continuing with Part Three"
window.Close
End Sub
</SCRIPT>
<body>
Hello
</body>
</html>
If you are courageous enough (or foolhardy enough) to call api's
from script, then that is another way to "Sleep" or "Do Events".
--- <snip> ---
' ================================================
' === "WRAPPERS" FOR API CALLS (DynaWrap style) ==
'
' the DynaWrap doc is rather inscrutable, but as best I can make out,
' DynaWrap can only accomodate ONE api declaration at a time.
' (If I'm wrong, maybe you experts can straighten me out on this).
'
' Assuming that my one-at-a-time hypothesis is correct,
' then one has two choices:
' - you need to set up a separate obj for EVERY api (ugh!), or
' - declare the api's to be used (one-at-a-time) as you go,
' which is what you see here (yes, it's "ugly")...
' ================================================
Function Sleep(mSec)
Set oDW = nothing ' clear any previous instance
Set oDW = CreateObject("DynamicWrapper") ' start over...
' register (declare) this flavor of api call...
oDW.Register "KERNEL32.DLL", "Sleep", "i=l", "f=s" ' no return value
oDW.Sleep(CLng(mSec)
End Function
Function DoEvents()
Set oDW = nothing ' clear any previous instance
Set oDW = CreateObject("DynamicWrapper") ' start over...
' register (declare) this flavor of api call...
oDW.Register "MSVBVM50.DLL", "rtcDoEvents", "f=s" ' no input or
return value
oDW.rtcDoEvents()
End Function
--- </snip> ---
cheers, jw
____________________________________________________________
You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)
--- <DynaWrap Boilerplate> ---
It is possible to declare-and-call an api from script,
but you must use a third-party control to do so,
or else write one yourself.
It has already been correctly pointed out that there
is no api-capability in "pure" script.
If you are willing to use a third-party control, then
one such control, called "DynaWrap", can be found on
Guenter Born's website (note: Guenter refers to it as
"DynaCall"). Here is the link to it:
http://people.freenet.de/gborn/WSHBazaar/WSHDynaCall.htm
On that page you will find a download for the control,
plus some code samples.
Note: you may find additional sample code by searching
the archives of the wsh and vbscript ng's.
Note also: DynaWrap does have its limitations. There are
certain things it can't do. For example, you can't call
api's which take typedefs as parameters, and you can't call
api's "by ordinal". But it will work for most of the
"usual suspects".
And finally, DynaWrap doesn't work entirely as advertised.
For example, it is supposed to allow for the declaration of
several api definitions in one instance of itself. I could
never get that to work (in win9x). You will need a new
instance of DynaWrap for every api, or else re-instantiate
the object for every api. Someday I'm going to learn enough
c++ to fix that...
--- </DynaWrap Boilerplate> ---
oops, make that: "oDW.Sleep(CLng(mSec))
I use the following sub-routine to perform a sleep operation in my HTA's:
Sub HTASleep(intSeconds)
Dim objShell, strCommand
Set objShell = CreateObject("Wscript.Shell")
strCommand = "%COMSPEC% /c ping -n " & 1 + intSeconds & " 127.0.0.1>nul"
objShell.Run strCommand, 0, True
Set objShell = Nothing
End Sub
Hope this helps,
B-Mann
For DoEvents...
Here's a hack^H^H^H^Htechnique that you can use since this is an HTA...
Sub DoNothing()
'Triggers screen updates in an HTA...
With CreateObject("WScript.Shell")
.run "%comspec% /c exit", 0, true
End With
End Sub
--
Michael Harris
Microsoft MVP Scripting