InputBox Function (Visual Basic)
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 Function InputBox( _ ByVal Prompt As String, _ Optional ByVal Title As String = "", _ Optional ByVal DefaultResponse As String = "", _ Optional ByVal Xpos As Integer = -1, _ Optional ByVal YPos As Integer = -1 _ ) As String
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 Class. |
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
Namespace: Microsoft.VisualBasic
Module: Interaction
Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)
Note: