VBScript InputBox Function

Definition and Usage

The InputBox function can display a dialog box where the user can enter text and/or click a button. If the user clicks the OK button or presses the Enter key on the keyboard, the InputBox function returns the text in the text box. If the user clicks the Cancel button, the function returns an empty string ("

Note:If both the helpfile and context parameters are specified, a help button will be added to the dialog box.

Tip:See MsgBox function.

Syntax

InputBox(prompt[,title][,default][,xpos][,ypos][,helpfile,context])
Parameter Description
prompt Required. The message displayed in the dialog box. The maximum length of the prompt is approximately 1024 characters, depending on the width of the characters used. If the prompt contains multiple lines, you can separate each line with a carriage return (Chr(13)), a line feed (Chr(10)), or a combination of both (Chr(13) & Chr(10)).
title Optional. A string expression that is displayed in the title bar of the dialog box. If title is omitted, the name of the application is displayed in the title bar.
default Optional. A string expression that is displayed in the text box and serves as the default response value when no other input is provided. If default is omitted, the text box is empty.
xpos Optional. A numeric expression that specifies the horizontal distance from the left edge of the dialog box to the left edge of the screen (in twips). If xpos is omitted, the dialog box is centered horizontally.
ypos Optional. A numeric expression that specifies the vertical distance from the top edge of the dialog box to the top edge of the screen (in twips). If ypos is omitted, the dialog box is displayed about one-third of the way down the screen vertically.
helpfile Optional. A string expression that identifies the help file that provides context-related help for the dialog box. If helpfile is provided, context must also be provided.
context Optional. A numeric expression that identifies the context number assigned to a help topic by the author of the help file. If context is provided, helpfile must also be provided.

Example

dim fname
fname=InputBox("Enter your name:")
MsgBox("Your name is " & fname)