sleep function 
Author Message
 sleep function

 This is a question that probably was addressed more than once, but I needed
now and probably I missed the answer.
I am trying to use the sleep function of Wscript, from inside an application
that runs the MS-VBScript engine. Since I am not using WSH directly
(Wscript.exe) the Wscript object is missing.

Does anyone know how to instantiate the Wscript object from inside the
application, so I can use the sleep function?

 Thanks, in advance.



Mon, 29 Sep 2003 23:14:23 GMT  
 sleep function

Quote:

>  This is a question that probably was addressed more than once, but
> I needed now and probably I missed the answer.
> I am trying to use the sleep function of Wscript, from inside an
> application that runs the MS-VBScript engine. Since I am not using
> WSH directly (Wscript.exe) the Wscript object is missing.

> Does anyone know how to instantiate the Wscript object from inside
> the application, so I can use the sleep function?

>  Thanks, in advance.

It can't be done, AFAIK.  Rather consider using the
InternetExplorer.Application object and it's setInterval() and or
setTimeout() methods.  I use setInterval in some HTA's, something like
this ...

   Dim publicID, oIE
   set oIE = CreateObject("InternetExplorer.Application")

  sub main
  ' code ...
  ' ...
  ' Sleep
    nWait = 5000 ' ms - for example
    publicID = oIE.setInterval("main_Next", nWait, "vbscript")
  end sub

  sub main_Next
    oIE.clearInterval publicID
  ' more code to be executed after delay
  ' ...

If the delay is needed in a loop, the Main_Next routine will need to
call the main routine after it clears the publicID.  Of course, there
will need to be code that exits the loop, as appropriate.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Mon, 29 Sep 2003 23:46:20 GMT  
 sleep function
Tom,

That gives you the functionality of a Timer object, not the equivalent of Sleep...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--



Mon, 29 Sep 2003 23:57:45 GMT  
 sleep function
The WScript intrinsic object isn't externally creatable.  Your host application will need to provide
the script engine with that kind of functionality just as wscript.exe and cscript.exe do as hosts
for script engines...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> This is a question that probably was addressed more than once, but I needed
> now and probably I missed the answer.
> I am trying to use the sleep function of Wscript, from inside an application
> that runs the MS-VBScript engine. Since I am not using WSH directly
> (Wscript.exe) the Wscript object is missing.

> Does anyone know how to instantiate the Wscript object from inside the
> application, so I can use the sleep function?

>  Thanks, in advance.



Mon, 29 Sep 2003 23:54:49 GMT  
 sleep function

Quote:

> Tom,

> That gives you the functionality of a Timer object, not the
> equivalent of Sleep...

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup instead.
> --

Sorry, I don't follow you.  It works like a Sleep for me - because I
break the code at the setInterval and end the first routine.   No code
is executed until the 'timer' goes off and calls the continuation code.
Isn't that like Sleep?  At least, that's how it appears to work in my
HTA's.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Tue, 30 Sep 2003 00:59:57 GMT  
 sleep function
WScript.Sleep works inline with executing code, giving up the thread's remaining time slice until it
wakes up and continues with the next statement.  WScript.Sleep isn't really completely asleep
though - it continues to process the message queue in order to be able to respond to events.  Sort
of like taking a lot of little cat naps ;-)...

What you are effectively doing is executing separate discontinuous checks of code as separate event
handlers (the repeating timeout event generated by setInterval)...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:


> > Tom,

> > That gives you the functionality of a Timer object, not the
> > equivalent of Sleep...

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

> > Please do not email questions - post them to the newsgroup instead.
> > --

> Sorry, I don't follow you.  It works like a Sleep for me - because I
> break the code at the setInterval and end the first routine.   No code
> is executed until the 'timer' goes off and calls the continuation code.
> Isn't that like Sleep?  At least, that's how it appears to work in my
> HTA's.

> Tom Lavedas
> -----------
> http://www.pressroom.com/~tglbatch/



Tue, 30 Sep 2003 03:46:22 GMT  
 sleep function
I don't mean to be dense or obstinate (I just am - bear with me ;o), but
I can't say that I understand the practical implications of what you are
saying.  It seems to me to be just semantics.  For example, I created
the little HTA below, that looks a bit like the old Win 3.x Clock.  It
just sits in the corner of my desktop counting away seconds while I work
in other windows, much as a Wscript would, if it were running a Do Loop
around a Sleep ...

<html>
  <HTA:APPLICATION ID="oClock"
    APPLICATIONNAME="Clock"  BORDER="normal"
    CAPTION="no"             ICON=""
    SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
    SCROLL="no"              SYSMENU="no"
    WINDOWSTATE="normal"
  >
<script language=vbscript>
  Dim PublicID

  sub window_onload()
    document.title = "Clock"
    resizeTo 100,75 :  moveTo 920, 5
    doit
  End sub

  sub doit
    if not IsEmpty(PublicID) Then clearInterval PublicID
    document.all.time.innerHTML = "<center><b>" & Time _
      & "</b></center>"
    PublicID = setInterval("doit", 450, "vbscript")
  end sub

</script></head><body bgcolor=LightSkyBlue>
<div id=time></div></center></body></html>

So, except for the fact that my 'Clock' has a 'console' on which it
displays the time, and a Wscript wouldn't, how is this different -
practically speaking?

(BTW, I just use Alt-F4 to close my 'Clock' app.)

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

Quote:

> WScript.Sleep works inline with executing code, giving up the
> thread's remaining time slice until it wakes up and continues with > the next statement.  WScript.Sleep isn't really completely asleep
> though - it continues to process the message queue in order to be
> able to respond to events.  Sort of like taking a lot of little cat
> naps ;-)...

> What you are effectively doing is executing separate discontinuous
> checks of code as separate event handlers (the repeating timeout
> event generated by setInterval)...

> --
> Michael Harris
> Microsoft.MVP.Scripting
> --

> Please do not email questions - post them to the newsgroup instead.
> --



> > > Tom,

> > > That gives you the functionality of a Timer object, not the
> > > equivalent of Sleep...

> > > --
> > > Michael Harris
> > > Microsoft.MVP.Scripting
> > > --

> > > Please do not email questions - post them to the newsgroup
> > > instead.
> > > --

> > Sorry, I don't follow you.  It works like a Sleep for me - because
> > I break the code at the setInterval and end the first routine.  
> > No code is executed until the 'timer' goes off and calls the
> > continuation code. Isn't that like Sleep?  At least, that's how it
> > appears to work in my HTA's.

> > Tom Lavedas
> > -----------
> > http://www.pressroom.com/~tglbatch/



Tue, 30 Sep 2003 04:24:33 GMT  
 sleep function
I still want to give it a shot and see if Tom's approach solves my problem.
Unfortunately I don't know that much of the DHTML Object model.

In the line:    PublicID = setInterval("doit", 450, "vbscript")
You can do this because you are running the script inside the context of the
HTA file.
What would be the way to write this line if the script is external to the IE
Object?
I've tried  publicID = oIE.document.parentwindow.setInterval("clearwait()",
1000 )
but it didn't work, I'm receiving a message asking for the object.

Basically what I am trying to do is, from a VBScript inside my host
application, open an IE Window, draw a drop down menu, wait for the user to
hit the Ok button and return the selected item to the VBScript.
It's working in the way I want it from a .vbs file using the sleep function
from WScript, unfortunately my host application doesn't have a sleep
function and I am trying to workaround this limitation.

Thanks, in advance.

Quote:
> <html>
>   <HTA:APPLICATION ID="oClock"
>     APPLICATIONNAME="Clock"  BORDER="normal"
>     CAPTION="no"             ICON=""
>     SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
>     SCROLL="no"              SYSMENU="no"
>     WINDOWSTATE="normal"

> <script language=vbscript>
>   Dim PublicID

>   sub window_onload()
>     document.title = "Clock"
>     resizeTo 100,75 :  moveTo 920, 5
>     doit
>   End sub

>   sub doit
>     if not IsEmpty(PublicID) Then clearInterval PublicID
>     document.all.time.innerHTML = "<center><b>" & Time _
>       & "</b></center>"
>     PublicID = setInterval("doit", 450, "vbscript")
>   end sub

> </script></head><body bgcolor=LightSkyBlue>
> <div id=time></div></center></body></html>

> So, except for the fact that my 'Clock' has a 'console' on which it
> displays the time, and a Wscript wouldn't, how is this different -
> practically speaking?

> (BTW, I just use Alt-F4 to close my 'Clock' app.)

> Tom Lavedas
> -----------
> http://www.pressroom.com/~tglbatch/


> > WScript.Sleep works inline with executing code, giving up the
> > thread's remaining time slice until it wakes up and continues with > the

next statement.  WScript.Sleep isn't really completely asleep

- Show quoted text -

Quote:
> > though - it continues to process the message queue in order to be
> > able to respond to events.  Sort of like taking a lot of little cat
> > naps ;-)...

> > What you are effectively doing is executing separate discontinuous
> > checks of code as separate event handlers (the repeating timeout
> > event generated by setInterval)...

> > --
> > Michael Harris
> > Microsoft.MVP.Scripting
> > --

> > Please do not email questions - post them to the newsgroup instead.
> > --




- Show quoted text -

Quote:

> > > > Tom,

> > > > That gives you the functionality of a Timer object, not the
> > > > equivalent of Sleep...

> > > > --
> > > > Michael Harris
> > > > Microsoft.MVP.Scripting
> > > > --

> > > > Please do not email questions - post them to the newsgroup
> > > > instead.
> > > > --

> > > Sorry, I don't follow you.  It works like a Sleep for me - because
> > > I break the code at the setInterval and end the first routine.
> > > No code is executed until the 'timer' goes off and calls the
> > > continuation code. Isn't that like Sleep?  At least, that's how it
> > > appears to work in my HTA's.

> > > Tom Lavedas
> > > -----------
> > > http://www.pressroom.com/~tglbatch/



Tue, 30 Sep 2003 05:27:03 GMT  
 sleep function
Okay, it took a while (and some experimentation), but I have FINALLY
tumbled to what Michael was trying to tell me.  The setInterval routine
will NOT work in this case because the instance of the
InternetExplorer.Application creates A NEW THREAD.  Thus, the interval
is executes outside of the context of the script that launches it.  That
means the originating script is NOT waiting for the IE timer to
timeout.  It will just move on, which defeats the whole purpose.

Alas, I haven't yet figured out a means of doing the job in your
context.  Let me think about it some more.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

Quote:

> I still want to give it a shot and see if Tom's approach solves my problem.
> Unfortunately I don't know that much of the DHTML Object model.

> In the line:    PublicID = setInterval("doit", 450, "vbscript")
> You can do this because you are running the script inside the context of the
> HTA file.
> What would be the way to write this line if the script is external to the IE
> Object?
> I've tried  publicID = oIE.document.parentwindow.setInterval("clearwait()",
> 1000 )
> but it didn't work, I'm receiving a message asking for the object.

> Basically what I am trying to do is, from a VBScript inside my host
> application, open an IE Window, draw a drop down menu, wait for the user to
> hit the Ok button and return the selected item to the VBScript.
> It's working in the way I want it from a .vbs file using the sleep function
> from WScript, unfortunately my host application doesn't have a sleep
> function and I am trying to workaround this limitation.

> Thanks, in advance.

> > <html>
> >   <HTA:APPLICATION ID="oClock"
> >     APPLICATIONNAME="Clock"  BORDER="normal"
> >     CAPTION="no"             ICON=""
> >     SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
> >     SCROLL="no"              SYSMENU="no"
> >     WINDOWSTATE="normal"

> > <script language=vbscript>
> >   Dim PublicID

> >   sub window_onload()
> >     document.title = "Clock"
> >     resizeTo 100,75 :  moveTo 920, 5
> >     doit
> >   End sub

> >   sub doit
> >     if not IsEmpty(PublicID) Then clearInterval PublicID
> >     document.all.time.innerHTML = "<center><b>" & Time _
> >       & "</b></center>"
> >     PublicID = setInterval("doit", 450, "vbscript")
> >   end sub

> > </script></head><body bgcolor=LightSkyBlue>
> > <div id=time></div></center></body></html>

> > So, except for the fact that my 'Clock' has a 'console' on which it
> > displays the time, and a Wscript wouldn't, how is this different -
> > practically speaking?

> > (BTW, I just use Alt-F4 to close my 'Clock' app.)

> > Tom Lavedas
> > -----------
> > http://www.pressroom.com/~tglbatch/


> > > WScript.Sleep works inline with executing code, giving up the
> > > thread's remaining time slice until it wakes up and continues with > the
> next statement.  WScript.Sleep isn't really completely asleep
> > > though - it continues to process the message queue in order to be
> > > able to respond to events.  Sort of like taking a lot of little cat
> > > naps ;-)...

> > > What you are effectively doing is executing separate discontinuous
> > > checks of code as separate event handlers (the repeating timeout
> > > event generated by setInterval)...

> > > --
> > > Michael Harris
> > > Microsoft.MVP.Scripting
> > > --

> > > Please do not email questions - post them to the newsgroup instead.
> > > --




> > > > > Tom,

> > > > > That gives you the functionality of a Timer object, not the
> > > > > equivalent of Sleep...

> > > > > --
> > > > > Michael Harris
> > > > > Microsoft.MVP.Scripting
> > > > > --

> > > > > Please do not email questions - post them to the newsgroup
> > > > > instead.
> > > > > --

> > > > Sorry, I don't follow you.  It works like a Sleep for me - because
> > > > I break the code at the setInterval and end the first routine.
> > > > No code is executed until the 'timer' goes off and calls the
> > > > continuation code. Isn't that like Sleep?  At least, that's how it
> > > > appears to work in my HTA's.

> > > > Tom Lavedas
> > > > -----------
> > > > http://www.pressroom.com/~tglbatch/



Tue, 30 Sep 2003 21:54:00 GMT  
 sleep function
Thanks to you, and Michael.

I really appreciate your help


Quote:
> Okay, it took a while (and some experimentation), but I have FINALLY
> tumbled to what Michael was trying to tell me.  The setInterval routine
> will NOT work in this case because the instance of the
> InternetExplorer.Application creates A NEW THREAD.  Thus, the interval
> is executes outside of the context of the script that launches it.  That
> means the originating script is NOT waiting for the IE timer to
> timeout.  It will just move on, which defeats the whole purpose.

> Alas, I haven't yet figured out a means of doing the job in your
> context.  Let me think about it some more.

> Tom Lavedas
> -----------
> http://www.pressroom.com/~tglbatch/


> > I still want to give it a shot and see if Tom's approach solves my
problem.
> > Unfortunately I don't know that much of the DHTML Object model.

> > In the line:    PublicID = setInterval("doit", 450, "vbscript")
> > You can do this because you are running the script inside the context of
the
> > HTA file.
> > What would be the way to write this line if the script is external to
the IE
> > Object?
> > I've tried  publicID =

oIE.document.parentwindow.setInterval("clearwait()",

- Show quoted text -

Quote:
> > 1000 )
> > but it didn't work, I'm receiving a message asking for the object.

> > Basically what I am trying to do is, from a VBScript inside my host
> > application, open an IE Window, draw a drop down menu, wait for the user
to
> > hit the Ok button and return the selected item to the VBScript.
> > It's working in the way I want it from a .vbs file using the sleep
function
> > from WScript, unfortunately my host application doesn't have a sleep
> > function and I am trying to workaround this limitation.

> > Thanks, in advance.

> > > <html>
> > >   <HTA:APPLICATION ID="oClock"
> > >     APPLICATIONNAME="Clock"  BORDER="normal"
> > >     CAPTION="no"             ICON=""
> > >     SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
> > >     SCROLL="no"              SYSMENU="no"
> > >     WINDOWSTATE="normal"

> > > <script language=vbscript>
> > >   Dim PublicID

> > >   sub window_onload()
> > >     document.title = "Clock"
> > >     resizeTo 100,75 :  moveTo 920, 5
> > >     doit
> > >   End sub

> > >   sub doit
> > >     if not IsEmpty(PublicID) Then clearInterval PublicID
> > >     document.all.time.innerHTML = "<center><b>" & Time _
> > >       & "</b></center>"
> > >     PublicID = setInterval("doit", 450, "vbscript")
> > >   end sub

> > > </script></head><body bgcolor=LightSkyBlue>
> > > <div id=time></div></center></body></html>

> > > So, except for the fact that my 'Clock' has a 'console' on which it
> > > displays the time, and a Wscript wouldn't, how is this different -
> > > practically speaking?

> > > (BTW, I just use Alt-F4 to close my 'Clock' app.)

> > > Tom Lavedas
> > > -----------
> > > http://www.pressroom.com/~tglbatch/


> > > > WScript.Sleep works inline with executing code, giving up the
> > > > thread's remaining time slice until it wakes up and continues with >
the
> > next statement.  WScript.Sleep isn't really completely asleep
> > > > though - it continues to process the message queue in order to be
> > > > able to respond to events.  Sort of like taking a lot of little cat
> > > > naps ;-)...

> > > > What you are effectively doing is executing separate discontinuous
> > > > checks of code as separate event handlers (the repeating timeout
> > > > event generated by setInterval)...

> > > > --
> > > > Michael Harris
> > > > Microsoft.MVP.Scripting
> > > > --

> > > > Please do not email questions - post them to the newsgroup instead.
> > > > --




> > > > > > Tom,

> > > > > > That gives you the functionality of a Timer object, not the
> > > > > > equivalent of Sleep...

> > > > > > --
> > > > > > Michael Harris
> > > > > > Microsoft.MVP.Scripting
> > > > > > --

> > > > > > Please do not email questions - post them to the newsgroup
> > > > > > instead.
> > > > > > --

> > > > > Sorry, I don't follow you.  It works like a Sleep for me - because
> > > > > I break the code at the setInterval and end the first routine.
> > > > > No code is executed until the 'timer' goes off and calls the
> > > > > continuation code. Isn't that like Sleep?  At least, that's how it
> > > > > appears to work in my HTA's.

> > > > > Tom Lavedas
> > > > > -----------
> > > > > http://www.pressroom.com/~tglbatch/



Tue, 30 Sep 2003 23:17:12 GMT  
 sleep function
This is one tough challenge.  It's much easier to create a modeless form
than a 'modal' one (as you well know).

I haven't figured out a satisfactory solution to a Sleep function for
your use yet, though I did make one kludge that sort of worked.
However, I have cobbled together an example of 'modal' form function
that doesn't require a Sleep loop.  Rather, it uses IE's showModalDialog
function.  That is, it displays a form and waits for the user to press a
button to submit the input back to the calling script.  

I only set it up for a simple one line input in the example, but it can
be modified to accept more, though didn't work out the details of
passing multiple arguments back, though concatenation of the results
into a delimited string and the use of the Split() function comes to
mind.   Also, the format of the form is not as 'pretty' as a 'real' IE
window can be, but it's still more editable than an InputBox.

' MAIN - For example, ...
MsgBox Form
' End of MAIN

Function Form
    Dim oIE, ofs
    set ofs = CreateObject("Scripting.FileSystemObject")
    sCurDir = ofs.GetAbsolutePathName(".")

    ofs.CreateTextFile("test.htm").write _
      "<script language=vbscript>" _
   &  "a=window.showModalDialog(""./form.htm"",""""," _
   &  """dialogHeight:150px; dialogWidth:300px"")" _
   &  "</script>"

    ofs.CreateTextFile("form.htm").write _
     "<html><head>" _
   & "<script language=vbscript>" _
   & "sub sendit:" _
   & "window.returnvalue=document.all.txt1.value:" _
   & "window.close:" _
   & "end sub" _
   & "</script></head><body bgcolor=Silver>&nbsp;<br><center>" _
   & "<input type=text id=txt1> &nbsp; " _
   & "<button onclick=sendit>Submit</button>" _
   & "</center></body></html>"

    Set oIE = CreateObject("InternetExplorer.Application")
    oIE.Navigate sCurDir & "\test.htm"
    do until oIE.ReadyState = 4 : Loop
    Form =  oIE.document.parentWindow.a
    ofs.DeleteFile "test.htm"
    ofs.DeleteFile "form.htm"
    oIE.quit
End Function

That's about the best I can do.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

Quote:

> Thanks to you, and Michael.

> I really appreciate your help



> > Okay, it took a while (and some experimentation), but I have FINALLY
> > tumbled to what Michael was trying to tell me.  The setInterval routine
> > will NOT work in this case because the instance of the
> > InternetExplorer.Application creates A NEW THREAD.  Thus, the interval
> > is executes outside of the context of the script that launches it.  That
> > means the originating script is NOT waiting for the IE timer to
> > timeout.  It will just move on, which defeats the whole purpose.

> > Alas, I haven't yet figured out a means of doing the job in your
> > context.  Let me think about it some more.

> > Tom Lavedas
> > -----------
> > http://www.pressroom.com/~tglbatch/


> > > I still want to give it a shot and see if Tom's approach solves my
> problem.
> > > Unfortunately I don't know that much of the DHTML Object model.

> > > In the line:    PublicID = setInterval("doit", 450, "vbscript")
> > > You can do this because you are running the script inside the context of
> the
> > > HTA file.
> > > What would be the way to write this line if the script is external to
> the IE
> > > Object?
> > > I've tried  publicID =
> oIE.document.parentwindow.setInterval("clearwait()",
> > > 1000 )
> > > but it didn't work, I'm receiving a message asking for the object.

> > > Basically what I am trying to do is, from a VBScript inside my host
> > > application, open an IE Window, draw a drop down menu, wait for the user
> to
> > > hit the Ok button and return the selected item to the VBScript.
> > > It's working in the way I want it from a .vbs file using the sleep
> function
> > > from WScript, unfortunately my host application doesn't have a sleep
> > > function and I am trying to workaround this limitation.

> > > Thanks, in advance.

> > > > <html>
> > > >   <HTA:APPLICATION ID="oClock"
> > > >     APPLICATIONNAME="Clock"  BORDER="normal"
> > > >     CAPTION="no"             ICON=""
> > > >     SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
> > > >     SCROLL="no"              SYSMENU="no"
> > > >     WINDOWSTATE="normal"

> > > > <script language=vbscript>
> > > >   Dim PublicID

> > > >   sub window_onload()
> > > >     document.title = "Clock"
> > > >     resizeTo 100,75 :  moveTo 920, 5
> > > >     doit
> > > >   End sub

> > > >   sub doit
> > > >     if not IsEmpty(PublicID) Then clearInterval PublicID
> > > >     document.all.time.innerHTML = "<center><b>" & Time _
> > > >       & "</b></center>"
> > > >     PublicID = setInterval("doit", 450, "vbscript")
> > > >   end sub

> > > > </script></head><body bgcolor=LightSkyBlue>
> > > > <div id=time></div></center></body></html>

> > > > So, except for the fact that my 'Clock' has a 'console' on which it
> > > > displays the time, and a Wscript wouldn't, how is this different -
> > > > practically speaking?

> > > > (BTW, I just use Alt-F4 to close my 'Clock' app.)

> > > > Tom Lavedas
> > > > -----------
> > > > http://www.pressroom.com/~tglbatch/


> > > > > WScript.Sleep works inline with executing code, giving up the
> > > > > thread's remaining time slice until it wakes up and continues with >
> the
> > > next statement.  WScript.Sleep isn't really completely asleep
> > > > > though - it continues to process the message queue in order to be
> > > > > able to respond to events.  Sort of like taking a lot of little cat
> > > > > naps ;-)...

> > > > > What you are effectively doing is executing separate discontinuous
> > > > > checks of code as separate event handlers (the repeating timeout
> > > > > event generated by setInterval)...

> > > > > --
> > > > > Michael Harris
> > > > > Microsoft.MVP.Scripting
> > > > > --

> > > > > Please do not email questions - post them to the newsgroup instead.
> > > > > --




> > > > > > > Tom,

> > > > > > > That gives you the functionality of a Timer object, not the
> > > > > > > equivalent of Sleep...

> > > > > > > --
> > > > > > > Michael Harris
> > > > > > > Microsoft.MVP.Scripting
> > > > > > > --

> > > > > > > Please do not email questions - post them to the newsgroup
> > > > > > > instead.
> > > > > > > --

> > > > > > Sorry, I don't follow you.  It works like a Sleep for me - because
> > > > > > I break the code at the setInterval and end the first routine.
> > > > > > No code is executed until the 'timer' goes off and calls the
> > > > > > continuation code. Isn't that like Sleep?  At least, that's how it
> > > > > > appears to work in my HTA's.

> > > > > > Tom Lavedas
> > > > > > -----------
> > > > > > http://www.pressroom.com/~tglbatch/



Wed, 01 Oct 2003 04:47:37 GMT  
 sleep function
Tom

Thank you for your help, I can see you can do whatever you want with DHTML
and scripting.
It's very good to have someone like you around.

Best Regards,


Quote:
> This is one tough challenge.  It's much easier to create a modeless form
> than a 'modal' one (as you well know).

> I haven't figured out a satisfactory solution to a Sleep function for
> your use yet, though I did make one kludge that sort of worked.
> However, I have cobbled together an example of 'modal' form function
> that doesn't require a Sleep loop.  Rather, it uses IE's showModalDialog
> function.  That is, it displays a form and waits for the user to press a
> button to submit the input back to the calling script.

> I only set it up for a simple one line input in the example, but it can
> be modified to accept more, though didn't work out the details of
> passing multiple arguments back, though concatenation of the results
> into a delimited string and the use of the Split() function comes to
> mind.   Also, the format of the form is not as 'pretty' as a 'real' IE
> window can be, but it's still more editable than an InputBox.

> ' MAIN - For example, ...
> MsgBox Form
> ' End of MAIN

> Function Form
>     Dim oIE, ofs
>     set ofs = CreateObject("Scripting.FileSystemObject")
>     sCurDir = ofs.GetAbsolutePathName(".")

>     ofs.CreateTextFile("test.htm").write _
>       "<script language=vbscript>" _
>    &  "a=window.showModalDialog(""./form.htm"",""""," _
>    &  """dialogHeight:150px; dialogWidth:300px"")" _
>    &  "</script>"

>     ofs.CreateTextFile("form.htm").write _
>      "<html><head>" _
>    & "<script language=vbscript>" _
>    & "sub sendit:" _
>    & "window.returnvalue=document.all.txt1.value:" _
>    & "window.close:" _
>    & "end sub" _
>    & "</script></head><body bgcolor=Silver>&nbsp;<br><center>" _
>    & "<input type=text id=txt1> &nbsp; " _
>    & "<button onclick=sendit>Submit</button>" _
>    & "</center></body></html>"

>     Set oIE = CreateObject("InternetExplorer.Application")
>     oIE.Navigate sCurDir & "\test.htm"
>     do until oIE.ReadyState = 4 : Loop
>     Form =  oIE.document.parentWindow.a
>     ofs.DeleteFile "test.htm"
>     ofs.DeleteFile "form.htm"
>     oIE.quit
> End Function

> That's about the best I can do.

> Tom Lavedas
> -----------
> http://www.pressroom.com/~tglbatch/


> > Thanks to you, and Michael.

> > I really appreciate your help



> > > Okay, it took a while (and some experimentation), but I have FINALLY
> > > tumbled to what Michael was trying to tell me.  The setInterval
routine
> > > will NOT work in this case because the instance of the
> > > InternetExplorer.Application creates A NEW THREAD.  Thus, the interval
> > > is executes outside of the context of the script that launches it.
That
> > > means the originating script is NOT waiting for the IE timer to
> > > timeout.  It will just move on, which defeats the whole purpose.

> > > Alas, I haven't yet figured out a means of doing the job in your
> > > context.  Let me think about it some more.

> > > Tom Lavedas
> > > -----------
> > > http://www.pressroom.com/~tglbatch/


> > > > I still want to give it a shot and see if Tom's approach solves my
> > problem.
> > > > Unfortunately I don't know that much of the DHTML Object model.

> > > > In the line:    PublicID = setInterval("doit", 450, "vbscript")
> > > > You can do this because you are running the script inside the
context of
> > the
> > > > HTA file.
> > > > What would be the way to write this line if the script is external
to
> > the IE
> > > > Object?
> > > > I've tried  publicID =
> > oIE.document.parentwindow.setInterval("clearwait()",
> > > > 1000 )
> > > > but it didn't work, I'm receiving a message asking for the object.

> > > > Basically what I am trying to do is, from a VBScript inside my host
> > > > application, open an IE Window, draw a drop down menu, wait for the
user
> > to
> > > > hit the Ok button and return the selected item to the VBScript.
> > > > It's working in the way I want it from a .vbs file using the sleep
> > function
> > > > from WScript, unfortunately my host application doesn't have a sleep
> > > > function and I am trying to workaround this limitation.

> > > > Thanks, in advance.

> > > > > <html>
> > > > >   <HTA:APPLICATION ID="oClock"
> > > > >     APPLICATIONNAME="Clock"  BORDER="normal"
> > > > >     CAPTION="no"             ICON=""
> > > > >     SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
> > > > >     SCROLL="no"              SYSMENU="no"
> > > > >     WINDOWSTATE="normal"

> > > > > <script language=vbscript>
> > > > >   Dim PublicID

> > > > >   sub window_onload()
> > > > >     document.title = "Clock"
> > > > >     resizeTo 100,75 :  moveTo 920, 5
> > > > >     doit
> > > > >   End sub

> > > > >   sub doit
> > > > >     if not IsEmpty(PublicID) Then clearInterval PublicID
> > > > >     document.all.time.innerHTML = "<center><b>" & Time _
> > > > >       & "</b></center>"
> > > > >     PublicID = setInterval("doit", 450, "vbscript")
> > > > >   end sub

> > > > > </script></head><body bgcolor=LightSkyBlue>
> > > > > <div id=time></div></center></body></html>

> > > > > So, except for the fact that my 'Clock' has a 'console' on which
it
> > > > > displays the time, and a Wscript wouldn't, how is this different -
> > > > > practically speaking?

> > > > > (BTW, I just use Alt-F4 to close my 'Clock' app.)

> > > > > Tom Lavedas
> > > > > -----------
> > > > > http://www.pressroom.com/~tglbatch/


> > > > > > WScript.Sleep works inline with executing code, giving up the
> > > > > > thread's remaining time slice until it wakes up and continues
with >
> > the
> > > > next statement.  WScript.Sleep isn't really completely asleep
> > > > > > though - it continues to process the message queue in order to
be
> > > > > > able to respond to events.  Sort of like taking a lot of little
cat
> > > > > > naps ;-)...

> > > > > > What you are effectively doing is executing separate
discontinuous
> > > > > > checks of code as separate event handlers (the repeating timeout
> > > > > > event generated by setInterval)...

> > > > > > --
> > > > > > Michael Harris
> > > > > > Microsoft.MVP.Scripting
> > > > > > --

> > > > > > Please do not email questions - post them to the newsgroup
instead.
> > > > > > --




> > > > > > > > Tom,

> > > > > > > > That gives you the functionality of a Timer object, not the
> > > > > > > > equivalent of Sleep...

> > > > > > > > --
> > > > > > > > Michael Harris
> > > > > > > > Microsoft.MVP.Scripting
> > > > > > > > --

> > > > > > > > Please do not email questions - post them to the newsgroup
> > > > > > > > instead.
> > > > > > > > --

> > > > > > > Sorry, I don't follow you.  It works like a Sleep for me -
because
> > > > > > > I break the code at the setInterval and end the first routine.
> > > > > > > No code is executed until the 'timer' goes off and calls the
> > > > > > > continuation code. Isn't that like Sleep?  At least, that's
how it
> > > > > > > appears to work in my HTA's.

> > > > > > > Tom Lavedas
> > > > > > > -----------
> > > > > > > http://www.pressroom.com/~tglbatch/



Wed, 01 Oct 2003 06:39:07 GMT  
 sleep function
Install ScriptX (commercial component but no license is required for what you need) from
www.meadroid.com...  It has a Wait method comparable to WScript.Sleep.

I still don't understand why you don't just implement a simple COM component in you own app that
provides a Sleep method and expose an instance of it to the script engine.  That's all WScript
does...

--
Michael Harris
Microsoft.MVP.Scripting
--

Please do not email questions - post them to the newsgroup instead.
--

Quote:

> Thanks to you, and Michael.

> I really appreciate your help



> > Okay, it took a while (and some experimentation), but I have FINALLY
> > tumbled to what Michael was trying to tell me.  The setInterval routine
> > will NOT work in this case because the instance of the
> > InternetExplorer.Application creates A NEW THREAD.  Thus, the interval
> > is executes outside of the context of the script that launches it.  That
> > means the originating script is NOT waiting for the IE timer to
> > timeout.  It will just move on, which defeats the whole purpose.

> > Alas, I haven't yet figured out a means of doing the job in your
> > context.  Let me think about it some more.

> > Tom Lavedas
> > -----------
> > http://www.pressroom.com/~tglbatch/


> > > I still want to give it a shot and see if Tom's approach solves my
> problem.
> > > Unfortunately I don't know that much of the DHTML Object model.

> > > In the line:    PublicID = setInterval("doit", 450, "vbscript")
> > > You can do this because you are running the script inside the context of
> the
> > > HTA file.
> > > What would be the way to write this line if the script is external to
> the IE
> > > Object?
> > > I've tried  publicID =
> oIE.document.parentwindow.setInterval("clearwait()",
> > > 1000 )
> > > but it didn't work, I'm receiving a message asking for the object.

> > > Basically what I am trying to do is, from a VBScript inside my host
> > > application, open an IE Window, draw a drop down menu, wait for the user
> to
> > > hit the Ok button and return the selected item to the VBScript.
> > > It's working in the way I want it from a .vbs file using the sleep
> function
> > > from WScript, unfortunately my host application doesn't have a sleep
> > > function and I am trying to workaround this limitation.

> > > Thanks, in advance.

> > > > <html>
> > > >   <HTA:APPLICATION ID="oClock"
> > > >     APPLICATIONNAME="Clock"  BORDER="normal"
> > > >     CAPTION="no"             ICON=""
> > > >     SHOWINTASKBAR="no"      SINGLEINSTANCE="yes"
> > > >     SCROLL="no"              SYSMENU="no"
> > > >     WINDOWSTATE="normal"

> > > > <script language=vbscript>
> > > >   Dim PublicID

> > > >   sub window_onload()
> > > >     document.title = "Clock"
> > > >     resizeTo 100,75 :  moveTo 920, 5
> > > >     doit
> > > >   End sub

> > > >   sub doit
> > > >     if not IsEmpty(PublicID) Then clearInterval PublicID
> > > >     document.all.time.innerHTML = "<center><b>" & Time _
> > > >       & "</b></center>"
> > > >     PublicID = setInterval("doit", 450, "vbscript")
> > > >   end sub

> > > > </script></head><body bgcolor=LightSkyBlue>
> > > > <div id=time></div></center></body></html>

> > > > So, except for the fact that my 'Clock' has a 'console' on which it
> > > > displays the time, and a Wscript wouldn't, how is this different -
> > > > practically speaking?

> > > > (BTW, I just use Alt-F4 to close my 'Clock' app.)

> > > > Tom Lavedas
> > > > -----------
> > > > http://www.pressroom.com/~tglbatch/


> > > > > WScript.Sleep works inline with executing code, giving up the
> > > > > thread's remaining time slice until it wakes up and continues with >
> the
> > > next statement.  WScript.Sleep isn't really completely asleep
> > > > > though - it continues to process the message queue in order to be
> > > > > able to respond to events.  Sort of like taking a lot of little cat
> > > > > naps ;-)...

> > > > > What you are effectively doing is executing separate discontinuous
> > > > > checks of code as separate event handlers (the repeating timeout
> > > > > event generated by setInterval)...

> > > > > --
> > > > > Michael Harris
> > > > > Microsoft.MVP.Scripting
> > > > > --

> > > > > Please do not email questions - post them to the newsgroup instead.
> > > > > --




> > > > > > > Tom,

> > > > > > > That gives you the functionality of a Timer object, not the
> > > > > > > equivalent of Sleep...

> > > > > > > --
> > > > > > > Michael Harris
> > > > > > > Microsoft.MVP.Scripting
> > > > > > > --

> > > > > > > Please do not email questions - post them to the newsgroup
> > > > > > > instead.
> > > > > > > --

> > > > > > Sorry, I don't follow you.  It works like a Sleep for me - because
> > > > > > I break the code at the setInterval and end the first routine.
> > > > > > No code is executed until the 'timer' goes off and calls the
> > > > > > continuation code. Isn't that like Sleep?  At least, that's how it
> > > > > > appears to work in my HTA's.

> > > > > > Tom Lavedas
> > > > > > -----------
> > > > > > http://www.pressroom.com/~tglbatch/



Wed, 01 Oct 2003 07:01:40 GMT  
 sleep function
Michael:

Quote:
> I still don't understand why you don't just implement a simple COM

component in you own app that

Quote:
> provides a Sleep method and expose an instance of it to the script engine.
That's all WScript
> does...

The reason is because unfortunately I am not in control of the host
application.
Anyway thanks for the tip.

Regards,



Wed, 01 Oct 2003 09:14:52 GMT  
 
 [ 14 post ] 

 Relevant Pages 

1. sleep function

2. Sleep function in vbscript????

3. sleep function

4. Sleep function

5. Sleep Function & FileSystemObject

6. ASP sleep function

7. sleep function

8. Is there a Sleep function??

9. Sleep function to run in vbscript?

10. I need simulate sleep() C function

11. wscript.sleep 1 and wscript.sleep 2

12. How to create a sleep in an HTA (wscript.sleep doesn't work in HTA...)

 

 
Powered by phpBB® Forum Software