Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Expireing Inputbox 1

Status
Not open for further replies.

Nitrous270

Technical User
Jul 27, 2002
67
0
0
US
Is it possible to have a visual basic script have an Input Box to accept a custom answer and if the user doesn't make an input within a specified time then it accepts a default?

This is the best piece of code I can come up with so far but the StrPtr() function seems to return an error no to mention its not timed in anyway. Any help would be appreciated. Thanks in advance.

Nitrous270


Dim Answer
Answer = InputBox(prompt:="Enter a value", Default:="Value")
If StrPtr(Answer) = 0 Then
MsgBox "You clicked cancel"
Else
MsgBox "You entered: " & Answer
End If
 
Hello Nitrous270,

It is not vbs. Check out vbs documentation on the inputbox.
[tt]
Dim Answer
Answer = InputBox("Enter a value","title", "Value")
If Answer = "" Then
MsgBox "You clicked cancel or you left the entry empty."
Else
MsgBox "You entered: " & Answer
End If
[/tt]
If you need a time limit, the native vbs solution can be something like this.
[1] Make a popup from wscript.shell popup method with a time limit.
[2] The pop up asks the user if need a custom setting for certain variable or else a default value is taken. Also make users know they have certain time to response.
[3.1] If clicked yes, the above inputbox appear.
[3.2] if no, default value is used.
[3.3] If timeout, it is assumed user accepts the default.

regards - tsuji
 
Thank you tsuji. Sometimes its just knowing what to search for anyway your answer led me to this website ...


And with that info I constructed this generic script. Basically the user has to answer "Yes", change the input, and click "Okay" in order to get anything but the default. This example will go for 5 seconds and then continue with the rest of the script if nothing is selected. Unless the user answers yes at which case the script will not continue until the user hits "Okay" or "Cancel" on the InputBox.

Thanks again tsuji,
Nitrous270


Dim WshShell
Dim intButton
Dim strInput

Set WshShell = CreateObject("WScript.Shell")

intButton = WshShell.Popup("Yes/No Timed Question, You have 5 seconds", 5, "Title", 4 + 32)

If intButton = 6 Then
strInput = InputBox("Prompt", "Title","Default")
If Len(strInput) = 0 Then
MsgBox "Default"
Else
MsgBox strInput
End If
Else
MsgBox "Default"
End If

Set WSHShell = Nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top