Input Box function
Input box function is used to retrieve a input from the user
Parameters
The input box function takes three parameters:
InputBox PromptText, DialogTitle, DefaultText
The PromptText is a string containing the text to be displayed as the prompt. The DialogTitle is a string containing the text to be displayed in the dialog’s title, and DefaultText is a string containing the text to be already displayed in the text box.
Description
The code below displays the dialog box
InputBox “Please enter the name”,”Enter Name”, “Michael”
However, we need to know what the user entered! The InputBox function returns a string, which is the text the user entered in the Input Box.
Dim Name As String
Name = InputBox (”Please enter the name”, _
“Enter Name”, “Michael”)
Msgbox “The name is ” & Name
This displays an input box asking the user for a name. When the user clicks OK then a Message Box will be displayed showing the text the user entered. You will notice that if you press cancel, the message box is still displayed. When the cancel button is pressed, the InputBox returns an empty string. You can edit the code so the message box is not displayed if the user presses cancel, or does not type anything:
Dim Name As String
Name = InputBox (”Please enter the name”, _
“Enter Name”, “Michael”)
‘ If Name is not empty, display the message box
If Not Name = “” Then Msgbox “The name is ” & Name
