Inputbox with timeout option / Pause 
Author Message
 Inputbox with timeout option / Pause

Hello,

Is is possible to create an InputBox with a default value which will be
assigned when no button is pressed during timeout-period ?

Regards,
Arjan van den Noort



Fri, 08 Aug 2003 22:45:12 GMT  
 Inputbox with timeout option / Pause

Quote:

> Hello,

> Is is possible to create an InputBox with a default value which will
> be assigned when no button is pressed during timeout-period ?

> Regards,
> Arjan van den Noort

For a stand alone script (WSH as the host), I can offer this kludge ...

wsh.echo "Done", InBoxWithTimeout("Timed InputBox", _
                 InputBox("Enter a test delay period (sec)"))

Function InBoxWithTimeout(sPrompt, nDelay)
  If (nDelay <> Empty) and (nDelay > 0) Then
    set oEnv = CreateObject("Wscript.Shell").Environment("SYSTEM")
    oEnv("Wait") = "TIMEOUT"
    set ofs = CreateObject("Scripting.FileSystemObject")
    ofs.CreateTextFile("C:\~tmp.vbs", True)_
      .Write "s=InputBox(""" & sPrompt & """)" & vbNewline & _
        "CreateObject(""Wscript.Shell"")" & _
          ".Environment(""System"")(""Wait"") = """" & s"
    CreateObject("WScript.Shell").Run "wscript //t:" & _
      CInt(nDelay) & " C:\~tmp.vbs ", 1, True
    ofs.DeleteFile "C:\~tmp.vbs"
    InBoxWithTimeOut = oEnv("Wait")
    oEnv("Wait") = ""
    set oEnv = Nothing
  Else
    InBoxWithTimeOut = InputBox(sPrompt)
  End if
End Function

It uses the system environment to return the input string from the
secondary procedure created in the function.  This should work in
98/NT/2000, but I don't believe it will work in Win 95 (or maybe it
requires WSH version 5.1+ in Win 95/98, I don't really know).  I tested
it in Win 98SE.  The only other alternative is to use a file or the
registry for communications, but I wanted to avoid that additional
complexity.

Also, the example is meant as a prototype, not a full featured
solution.  Foe example, I didn't include all of the normal arguments in
the secondary Inputbox, though they can be added, but again this
complicates things in that the InBoxWithTimeout call cannot accept
optional arguments, while the standard InputBox does.

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



Sat, 09 Aug 2003 02:33:36 GMT  
 Inputbox with timeout option / Pause
Thanks a lot. I will try your suggestion.
I did expect there was a sort of timing function in WSH which could be used.
Maybe there are more suggestions ?
Regards,
Arjan


Quote:

> > Hello,

> > Is is possible to create an InputBox with a default value which will
> > be assigned when no button is pressed during timeout-period ?

> > Regards,
> > Arjan van den Noort

> For a stand alone script (WSH as the host), I can offer this kludge ...

> wsh.echo "Done", InBoxWithTimeout("Timed InputBox", _
>                  InputBox("Enter a test delay period (sec)"))

> Function InBoxWithTimeout(sPrompt, nDelay)
>   If (nDelay <> Empty) and (nDelay > 0) Then
>     set oEnv = CreateObject("Wscript.Shell").Environment("SYSTEM")
>     oEnv("Wait") = "TIMEOUT"
>     set ofs = CreateObject("Scripting.FileSystemObject")
>     ofs.CreateTextFile("C:\~tmp.vbs", True)_
>       .Write "s=InputBox(""" & sPrompt & """)" & vbNewline & _
>         "CreateObject(""Wscript.Shell"")" & _
>           ".Environment(""System"")(""Wait"") = """" & s"
>     CreateObject("WScript.Shell").Run "wscript //t:" & _
>       CInt(nDelay) & " C:\~tmp.vbs ", 1, True
>     ofs.DeleteFile "C:\~tmp.vbs"
>     InBoxWithTimeOut = oEnv("Wait")
>     oEnv("Wait") = ""
>     set oEnv = Nothing
>   Else
>     InBoxWithTimeOut = InputBox(sPrompt)
>   End if
> End Function

> It uses the system environment to return the input string from the
> secondary procedure created in the function.  This should work in
> 98/NT/2000, but I don't believe it will work in Win 95 (or maybe it
> requires WSH version 5.1+ in Win 95/98, I don't really know).  I tested
> it in Win 98SE.  The only other alternative is to use a file or the
> registry for communications, but I wanted to avoid that additional
> complexity.

> Also, the example is meant as a prototype, not a full featured
> solution.  Foe example, I didn't include all of the normal arguments in
> the secondary Inputbox, though they can be added, but again this
> complicates things in that the InBoxWithTimeout call cannot accept
> optional arguments, while the standard InputBox does.

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



Sun, 10 Aug 2003 23:20:10 GMT  
 Inputbox with timeout option / Pause
Might be nice, but AFAIK the only timed user interaction control
provided by scripting is the WSHShell.Popup function, which doesn't
provide for user input.

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


Quote:

> Thanks a lot. I will try your suggestion.
> I did expect there was a sort of timing function in WSH which could
> be used. Maybe there are more suggestions ?
> Regards,
> Arjan




> > > Hello,

> > > Is is possible to create an InputBox with a default value which will
> > > be assigned when no button is pressed during timeout-period ?

> > > Regards,
> > > Arjan van den Noort

> > For a stand alone script (WSH as the host), I can offer this kludge ...

> > wsh.echo "Done", InBoxWithTimeout("Timed InputBox", _
> >                  InputBox("Enter a test delay period (sec)"))

> > Function InBoxWithTimeout(sPrompt, nDelay)
> >   If (nDelay <> Empty) and (nDelay > 0) Then
> >     set oEnv = CreateObject("Wscript.Shell").Environment("SYSTEM")
> >     oEnv("Wait") = "TIMEOUT"
> >     set ofs = CreateObject("Scripting.FileSystemObject")
> >     ofs.CreateTextFile("C:\~tmp.vbs", True)_
> >       .Write "s=InputBox(""" & sPrompt & """)" & vbNewline & _
> >         "CreateObject(""Wscript.Shell"")" & _
> >           ".Environment(""System"")(""Wait"") = """" & s"
> >     CreateObject("WScript.Shell").Run "wscript //t:" & _
> >       CInt(nDelay) & " C:\~tmp.vbs ", 1, True
> >     ofs.DeleteFile "C:\~tmp.vbs"
> >     InBoxWithTimeOut = oEnv("Wait")
> >     oEnv("Wait") = ""
> >     set oEnv = Nothing
> >   Else
> >     InBoxWithTimeOut = InputBox(sPrompt)
> >   End if
> > End Function

> > It uses the system environment to return the input string from the
> > secondary procedure created in the function.  This should work in
> > 98/NT/2000, but I don't believe it will work in Win 95 (or maybe it
> > requires WSH version 5.1+ in Win 95/98, I don't really know).  I tested
> > it in Win 98SE.  The only other alternative is to use a file or the
> > registry for communications, but I wanted to avoid that additional
> > complexity.

> > Also, the example is meant as a prototype, not a full featured
> > solution.  Foe example, I didn't include all of the normal arguments in
> > the secondary Inputbox, though they can be added, but again this
> > complicates things in that the InBoxWithTimeout call cannot accept
> > optional arguments, while the standard InputBox does.

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



Sun, 10 Aug 2003 23:56:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. InputBox vs. InputBox$

2. changing select options based on previously selected options

3. remove method for options not removing selected option.

4. Option Explicit/Option Strict Settings?

5. Question about Option Strict/Option Explicit

6. About PDS /G2 option and VBDOS /G2 and /G3 option

7. option explicit or no option explicit?

8. Option group/option button

9. Option Group/Option Button

10. how to pause

11. pause PS/PDF drawing

12. Pause PS/PDF drawing

 

 
Powered by phpBB® Forum Software