
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/