I have a VB script which is called by internet explorer in response to a
context menu selection. I used the techinques in this article:
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/ext/tutorials/context.asp
In my script, I can do lots of things but unlike VB scripts run from the
command line I can't do things like "wscript sleep 1000". If I try I get
"Error: Object required: 'WScript'".
So how can I use wscript features from an Internet Explorer VB script?
Thanks!
Grant Schenck
Actually, ScriptX (from www.meadroid.com) has a basic free feature subset
(no license required except for mostly advanced printing/page layout
features). In the free subset is a Wait method that behaves like
WScript.Sleep.
--
Michael Harris
Microsoft MVP Scripting
You are correct that there is no native "sleep" time function available, but
there are third party controls that can be installed. I use "ASPTime.dll," which
has been around for years. Although as the name implies, it is intended for
server side use, it works equally well for client side script.
http://www.cs.niu.edu/%7Ez951259/comlinks.html
There are probably other, newer, fancier ones around, but if it ain't broke...
--
Crash
"You can't build a reputation on what you're going to do."
~ Henry Ford ~
Sub to call sleep method:
Public Sub Sleep(MSecs)
Dim Ret, SH
Set SH = CreateObject("WScript.Shell")
On Error Resume Next
Ret = SH.Run("sleeper.vbs " & MSecs, , True)
Set SH = Nothing
End Sub
--------------------------------------
The second script, named "sleeper.vbs" needs to be
in the same folder. Its content is like so:
Dim Arg
on error resume next
Arg = WScript.Arguments(0)
wscript.sleep Arg
To use the method, just call the following from within
your first script:
Sleep x
'-- where x is number of milliseconds.
I kind of worked around it by invoking a second script from the first:
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strCommandLine, 0
However, I'm now wondering if there is some way to use the WScript shell to
invoke commands like Sleep().
Any ideas?
Regards,
Grant Schenck
"JTW" <News...@Dx21.com> wrote in message
news:e11T$8tTGH...@TK2MSFTNGP09.phx.gbl...
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run strCommandLine, 0
Then in the new script I can do sleeps just fine.
However, I was wondering if there was some way to create the WScript shell
and use it from the client script to somehow invoke sleep. This way I can
have one script rather then two.
--
Grant Schenck
http://grantschenck.tripod.com
""Crash" Dummy" <dva...@deathstar.mil> wrote in message
news:%23%23GhwSuT...@tk2msftngp13.phx.gbl...
If you are just interested in a non processor intensive sleep, then an
alternate approach is to use (the javascript) window.setTimeout the IE
provides. Of course it means an architectural change in your function
because your function will have to stop at the point that it starts to
sleep, and then start again (or have another one start) when the
setTimeout fires. But that's very often the appropriate architecture
anyway. Course I don't recommend this cross language hopping if you
can avoid it...
Here's a starter script to get you going:
<script type='text/javascript'>
function waitFor(millisecs) {
alert(millisecs);
window.setTimeout(momDispatch, millisecs); }
function momDispatch() {
mom2(" Brush your teeth"); }
</script>
<script type='text/vbscript'>
Dim savedVal
Function mom()
MsgBox "Hi mom - please wait"
savedVal = "Honey, I'm baaaaack"
waitFor(1000) 'in milliseconds
End Function
Function mom2 (jsVal)
MsgBox savedVal + vbCrLf + jsVal
End Function
mom
</script>
Csaba Gabor from Vienna
you'll have to cut the process in two (or more if you want to use the sleep
more often.
Or alternatively make your function state driven, which so that it can be be
called multiple times and depending on a global state will process a
different section of your code.
Below is an example of how I do it, All you need to do is replace
YourFunction in the function ItsTime and from your code you call
StartProcess(Yourfunction) and
(I have clipped it out of existing code, I think it will function as is, but
maybe overlooked something.
dim gStatusTimer
Function StartStatusTimer
if gStatusTimer = 0 Then
gStatusTimer = window.setInterval("ItsTime()", 1000)
End If
End Function
Function StopStatusTimer
if gStatusTimer <> 0 Then
window.clearInterval gStatusTimer
gStatusTimer = 0
end If
End Function
Dim gProcessName
Sub StartProcess(sProcessName)
gProcessName = sProcessName
End Sub
Function AtLeastOneMachineInstalling
AtLeastOneMachineInstalling = True
End Function
Function ItsTime
'Stop the timer to avoid a timer event during a lengthy process.
StopStatusTimer
If Len(gProcessName) > 0 Then
sTemp = gProcessName
gProcessName = ""
Select Case sTemp
Case "YourFunction"
YourFunction
Case Else
Msgbox "Programming error: process called: " & sTemp
End Select
End If
StartStatusTimer
End Function
"Grant Schenck" wrote:
> .
>
Based on the code below, I'm not clear what the script is doing while this
periodic timer events happen?
For example, presumably after I kick off some activity which I want to check
up on later I call your StartStatusTimer function. Then what do I do? What
does the script wait on so that the timer interval task can get control?
By the way, the COM object I'm interfacing with generates an event. Can
somehow handle that directly from VB script and if so, again, what does is
my script doing when it is in the mode waiting for events?
Thanks!
--
Grant Schenck
http://grantschenck.tripod.com
"wimZ" <wi...@discussions.microsoft.com> wrote in message
news:1249C51B-CDDE-4110...@microsoft.com...
t0 = timer
ccSleep 5
MsgBox "Sleep duration: " & vbCrlf & vbCrlf & timer - t0 & " seconds."
Sub ccSleep(seconds)
set oShell = CreateObject("Wscript.Shell")
cmd = "%COMSPEC% /c ping -n " & 1 + seconds & " 127.0.0.1>nul"
oShell.Run cmd,0,1
End Sub
Obtained from the Rube Goldberg Memorial Scripting Page:
http://www.mvps.org/scripting/rube/index.htm
Look for "A Synthetic Sleep Function."
HTH.
- Dave
this is the only real working sleep function.
The 'simulation' with timer functions is not a real sleep at all.
(Unfortunately.)
Well, in IE7.0, the sleep function doesn't work anymore. So maybe you
shouldn't use it. I use it and probably a have to do a total rebuild of my
application when IE7.0 has no sleep functionality anymore.
(I wonder why in al those years no standard sleep function is built in IE
(and FireFox),
with all the asynchronous XML requests and form post we lack a sleep
function.)
"Robin P" <Rob...@discussions.microsoft.com> wrote in message
news:26066040-0A27-4C7E...@microsoft.com...
#### pause.html #####
<HTML>
<BODY onload="test()">
<SCRIPT LANGUAGE="VBScript">
Function pause(numberMillis)
Dim dialogScript
dialogScript = "window.setTimeout(" & " function () { window.close(); }, "
& numberMillis & ");"
window.showModalDialog("javascript:document.writeln(" & """<script>" &
dialogScript & "<" + "/script>"")")
End Function
Function test()
window.alert("Start")
pause (3000)
window.alert("End after (about) 3 seconds")
End Function
</SCRIPT>
</BODY>
</HTML>
#####################
(javascript: is now used but there is no doubt it could be converted to
vbscript:
but this is just an example...
good luck!
Any ideas?
Thanks
--
Grant Schenck
"Robin P" <Rob...@discussions.microsoft.com> wrote in message
news:5854883F-54CA-4A57...@microsoft.com...
maybe you did a copy and paste, make sure the newlines are at the right
place( they are not at the right place after copy/paste)
it works for me (in IE 6.0)
so it should work for you.