Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

HTA and Wscript.Sleep

155 views
Skip to first unread message

Fred Newtz

unread,
Jun 2, 2008, 4:51:35 PM6/2/08
to
I am running Windows XP and writing a little application using VBScript and
a HTA. Is there something I can do to get wscript.sleep to work? Update
any files on my system or anything? This is driving me nuts. I need to
sleep without eating up my CPU as the computer is a eeePc 900 and it only
has a 650mhz Celeron in there. Looping kills me and pretty much kills any
application I am waiting for in the process.

Thanks,

Fred

mr_unreliable

unread,
Jun 2, 2008, 6:11:52 PM6/2/08
to
Fred, if you search the archives of this ng, you will find various
"work-arounds" that will simulate "sleep" in "pure" script.

http://groups.google.com/advanced_search

If you don't mind using a third-party control, then meadroid's
"scriptx" control has a sleep method:

http://www.meadroid.com/scriptx/about.asp

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but,
no guarantee the answers will be applicable to the questions)

Reventlov

unread,
Jun 2, 2008, 6:16:07 PM6/2/08
to

wscript object is not available because hta's are run from mshta.exe and not from
wscript.exe
write a sleep.vbs file with the sleep command in it and run it from your hta.
Giovanni.
--
Giovanni Cenati (Bergamo, Italy)
Write to "Reventlov" at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

MikeB

unread,
Jun 2, 2008, 7:08:21 PM6/2/08
to

"Fred Newtz" <fne...@natlgs.com> wrote in message
news:B3Z0k.4108$JL2....@fe20.usenetserver.com...

In addition to the other suggestions, if all you are doing is "sleeping" for
a time period to check on something in a loop, remember you can also use
javascript in the same HTA and as such you can use the setTimeout and
clearTimeout methods.
In an HTA, you can call J(ava)Script from VBscript and vice / versa.

Examples of setTimeout and clearTimeout methods.
http://www.w3schools.com/js/js_timing.asp

> Thanks,
>
> Fred
>


Fred Newtz

unread,
Jun 2, 2008, 9:31:16 PM6/2/08
to
But can I call a jscript routine from a vbscript routine?

Or can I only call it from one of the html objects in my code? Like in an
onclick or other event?


Thanks,

Fred

MikeB

unread,
Jun 2, 2008, 11:26:39 PM6/2/08
to

"Fred Newtz" <fne...@natlgs.com> wrote in message
news:Q911k.48438$wE.1...@fe72.usenetserver.com...

> But can I call a jscript routine from a vbscript routine?
>
> Or can I only call it from one of the html objects in my code? Like in an
> onclick or other event?

********begin Code**********

<html>

<HEAD>
<TITLE>This is the Application Caption</TITLE>

<SCRIPT type="text/jscript">
// Always Set Size Here to Avoid Flicker
var iwidth = 480;
var iheight = 400
window.moveTo( (window.screen.width - iwidth)/ 2, (window.screen.height -
iheight)/ 2);
window.resizeTo(iwidth,iheight);
</SCRIPT>

<HTA:APPLICATION ID="oApp"
APPLICATIONNAME="Splash Screen"
BORDER="thick"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
CAPTION="YES"
ICON="C:\Program Files\RBTI\RBG7\Samples\Icons\win1.ico"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
SCROLL="NO"
WINDOWSTATE="normal">

<script type="text/vbscript">

function CloseQuestion()
if msgbox("Should I Close This Window?", vbYesNo, "HTA - CloseOrNot") = vbYes
then
JSFunc("Quitting Now!")
end if
end function


Sub CallItQuits()

'Set SomeObjectCreated=Nothing
'Set SomeOtherObjectCreated=Nothing
'Set AnyObjectCreatedStillInstantiated=Nothing

window.Close()

end sub

</script>
<SCRIPT type="text/jscript">
function JSFunc(valIN)
{
alert(valIN);
CallItQuits();
}
</SCRIPT>
</HEAD>

<body >
<input type="button" value="How To Close HTA" onclick="CloseQuestion()">

</body>

</html>

*******End code*********

> Thanks,
>
> Fred
>


Joe Fawcett

unread,
Jun 3, 2008, 3:13:33 AM6/3/08
to
"Fred Newtz" <fne...@natlgs.com> wrote in message
news:Q911k.48438$wE.1...@fe72.usenetserver.com...
setTimeout isn't a JavaScript method, it's a method of the window object so
can be called from JavaScript or VBScript.

--

Joe Fawcett (MVP - XML)

http://joe.fawcett.name


mayayana

unread,
Jun 3, 2008, 8:25:19 AM6/3/08
to
> But can I call a jscript routine from a vbscript routine?
>
You're getting mainly VBS answers because this is a
VBS group. If you want javascript answers you
should post to a javascript group.


MikeB

unread,
Jun 3, 2008, 10:47:39 AM6/3/08
to

"mayayana" <mayaXX...@mindXXspring.com> wrote in message
news:eXMIMTX...@TK2MSFTNGP05.phx.gbl...

So he goes to a J(ava)Script group and asks the inverse and gets the same
answer.

It would have been appropriate to just answer the question, since most of his
subject matter related to VBScript and HTA. "Anyone" could give your response.

>
>


Fred Newtz

unread,
Jun 3, 2008, 4:45:29 PM6/3/08
to
No. I want VBScript answers. I just need to sleep. Or something that
works just as well as sleep does with out eating up all of my CPU cycles.

Thanks,

Fred

mayayana

unread,
Jun 3, 2008, 7:38:39 PM6/3/08
to
> No. I want VBScript answers. I just need to sleep. Or something that
> works just as well as sleep does with out eating up all of my CPU cycles.
>

Woops. Sorry. I misread, thinking you had
asked for javascript in the first place.

I use the same method Reventlov mentioned. It
shells to a separate script, allowing you use
Sleep in an HTA. It works because the last
parameter of Run (True) causes your script
to wait until the call returns.

This is called from the HTA or from an included
VBS file:

'--------------------------------
Sub Sleep1(MSecs)
Dim SH, Ret
On Error Resume Next
Set SH = CreateObject("WScript.Shell")
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
End If
End Sub
'--------------------------------

You call it like so: Sleep1 5000 '-- 5 second pause.

Then you have a file named sleeper.vbs in the
same folder with the HTA. The entire content
of sleeper.vbs is this:

'---------------------
Dim Arg
on error resume next
Arg = WScript.Arguments(0)
wscript.sleep Arg
'---------------------


Fred Newtz

unread,
Jun 3, 2008, 8:48:55 PM6/3/08
to
You make it seem so easy. It seems pretty juvenile that we have to do such
an easy hack, but whatever works. Thanks for the head pull out of the rear.


Thanks,

Fred

mayayana

unread,
Jun 3, 2008, 11:39:01 PM6/3/08
to
> It seems pretty juvenile that we have to do such
> an easy hack, but whatever works.

Yes, it's remarkable how much can be done with
script, but much of it is pretty ugly. :)


0 new messages