Displays a prompt in a dialog box, waits for the user to input text or click
a button, and returns a String containing the contents of the text box.
Following is an expanded InputBox

Syntax :
memory_variable = InputBox (prompt[,title][,default])
memory_variable is a variant data type but typically it is declared as string,
which accept the message input by the users. The arguments are explained as follows:
-
Prompt - String expression displayed as the message in the dialog box.
If prompt consists of more than one line, you can separate the lines using the
vbCrLf constant
-
Title - String expression displayed in the title bar of the dialog box.
If you omit the title, the application name is displayed in the title bar
-
default-text - The default text that appears in the input field where
users can use it as his intended input or he may change to the message he wish
to key in.
-
x-position and y-position - the position or the coordinate of the input
box.
Following example demonstrates the use of InputBox function
* Open a new project and save the Form as InputBox.frm and save the Project as
InputBox.vbp
* Design the application as shown below.
| Object |
Property |
Setting |
| Form
|
Caption
Name |
InputBox test
frmInputBox |
| Label
|
Caption
Name |
You entered
lbl1 |
| Label
|
Caption
Name
BorderStyle |
( empty)
lbl2
1-Fixed Single |
| CommandButton
|
Caption
Name |
OK
cmdOK |

Following code is entered in cmdOK_Click ( ) event
Private Sub cmdok_Click()
Dim ans As String
ans = InputBox("Enter something to be displayed in the label", "Testing",
0)
If ans = "" Then
lbl2.Caption = "No message"
Else
lbl2.Caption = ans
End If
End Sub
Save and run the application. As soon as you click the OK button you will get
the following InputBox

Here I have entered "Hello World" in text field. As soon as you click
OK the output is shown as shown below

( Download the source code )