In this tutorial, we will be talking about the Input Box in vbscript. The Input Box is a valuable function because it allows the user to give more feedback back to the VbScript than the Message Box. Specifically, you can enter characters for the Input Box, but you can only click on a button for Message Box. To re-iterate, the function of the Input Box is to give text input back to the VbScript, where as the function of the Message Box is to show a message while allowing limited input through buttons.
Input is important because it gives us more control over what the VbScript can do. To understand the value of input, imagine if you only had 4 keys versus a full set of keys on your keyboard. What we are able to do with computers is highly dependent on the input we are able to give it.
Input Box Format:
InputBox "The Message","The Title","The Input Field", xposition, yposition
An example of a Input Box script:
InputBox "What is your name?"
To put in a title for an input box:
InputBox "What is your name?","Information!"
To keep a preset value in the empty Input field:
InputBox "What is your name?","Information!","Name goes here"
You can also control what position the Input Box appears on the screen.
InputBox "What is your name?","Information!","Name goes here",500,500
Demonstration (I start talking about the positioning at the 1 minute mark):
Now if we want to set the Input Box to give us feedback, we have to store what is typed into the input field as a variable:
Option Explicit Dim name name = InputBox("What is your name?","Information!") MsgBox name,vbOKOnly,"This is your name."
Note that the () tells the vbscript what is included for the inputbox, which is equal to the name variable.
Clicking Cancel results in an empty message box, because there was no input. But Clicking OK stores the text in the name variable. And the message box spits back out what the name variable is: