The InputBox( ) function


InputBox( ) is a function which displays a dialog box with a prompt and then waits for the user to enter text or choose the OK or Cancel buttons and finally it return the contents of the textbox.

The syntax for using an input box is:

returnvalue = InputBox(prompt, title, default, xpos, ypos, helpfile, context)

Argument What it is Description
prompt The prompt (question) that appears in the dialog box. If necessary, the prompt can be broken into multiple line using the carriage return or line feed character (vbCrLf).
title The title of the dialog box. If leave blank, the application's name is display as the title.
default The default input (if any). If the input is anticipated, use this to display it when the dialog is first opened.
xpos, ypos The coordinate of the upper left corner of the dialog box. If not specified, the dialog will be display anywhere on the screen.
helpfile The name of the help file. Provide context sensitive help for the dialog box.
context The number within the help file. Assigned to the specific topic.
returnvalue The variable you choose to store the string entered by the user.

Remember, the input box returns a string, not a number. If you want a number, you must convert the returnvalue variable to a number using the Val( ) function.
ie: number = Val(returnvalue)

This is how an InputBox( ) function works:

Here is an example of the use of an InputBox( ) function ...

firstname = InputBox("Please enter a name", "Friendly Farmacy")

If firstname = "Bart" Then
    MsgBox "Go away Bart"
End If