Edit

Share via


Interaction.InputBox(String, String, String, Int32, Int32) Method

Definition

Displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a string containing the contents of the text box.

public static string InputBox (string Prompt, string Title = "", string DefaultResponse = "", int XPos = -1, int YPos = -1);
static member InputBox : string * string * string * int * int -> string
Public Function InputBox (Prompt As String, Optional Title As String = "", Optional DefaultResponse As String = "", Optional XPos As Integer = -1, Optional YPos As Integer = -1) As String

Parameters

Prompt
String

Required String expression displayed as the message in the dialog box. The maximum length of Prompt is approximately 1024 characters, depending on the width of the characters used. If Prompt consists of more than one line, you can separate the lines using a carriage return character (Chr(13)), a line feed character (Chr(10)), or a carriage return/line feed combination (Chr(13) & Chr(10)) between each line.

Title
String

Optional. String expression displayed in the title bar of the dialog box. If you omit Title, the application name is placed in the title bar.

DefaultResponse
String

Optional. String expression displayed in the text box as the default response if no other input is provided. If you omit DefaultResponse, the displayed text box is empty.

XPos
Int32

Optional. Numeric expression that specifies, in twips, the distance of the left edge of the dialog box from the left edge of the screen. If you omit XPos, the dialog box is centered horizontally.

YPos
Int32

Optional. Numeric expression that specifies, in twips, the distance of the upper edge of the dialog box from the top of the screen. If you omit YPos, the dialog box is positioned vertically approximately one-third of the way down the screen.

Returns

Displays a prompt in a dialog box, waits for the user to input text or click a button, and then returns a string containing the contents of the text box.

Examples

This example shows various ways to use the InputBox function to prompt the user to enter a value. If the x and y positions are omitted, the dialog box is automatically centered for the respective axes. The variable MyValue contains the value entered by the user if the user clicks OK or presses the ENTER key.

Dim message, title, defaultValue As String
Dim myValue As Object
' Set prompt.
message = "Enter a value between 1 and 3"
' Set title.
title = "InputBox Demo"
defaultValue = "1"   ' Set default value.

' Display message, title, and default value.
myValue = InputBox(message, title, defaultValue)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is "" Then myValue = defaultValue

' Display dialog box at position 100, 100.
myValue = InputBox(message, title, defaultValue, 100, 100)
' If user has clicked Cancel, set myValue to defaultValue
If myValue Is "" Then myValue = defaultValue

Remarks

If the user clicks Cancel, a zero-length string is returned.

To specify more than the first argument, you must use the InputBox function in an expression. If you omit any positional arguments, you must retain the corresponding comma delimiter.

Note

The InputBox function requires UIPermission at the SafeTopLevelWindows level, which may affect its execution in partial-trust situations. For more information, see Requesting Permissions and UIPermission .

Applies to

See also