Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Interaction Class
 InputBox Method
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Interaction..::.InputBox Method

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.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Visual Basic (Declaration)
<HostProtectionAttribute(SecurityAction.LinkDemand, Resources := HostProtectionResource.UI)> _
Public Shared Function InputBox ( _
    Prompt As String, _
    Title As String, _
    DefaultResponse As String, _
    XPos As Integer, _
    YPos As Integer _
) As String
Visual Basic (Usage)
Dim Prompt As String
Dim Title As String
Dim DefaultResponse As String
Dim XPos As Integer
Dim YPos As Integer
Dim returnValue As String

returnValue = Interaction.InputBox(Prompt, _
    Title, DefaultResponse, XPos, YPos)
C#
[HostProtectionAttribute(SecurityAction.LinkDemand, Resources = HostProtectionResource.UI)]
public static string InputBox(
    string Prompt,
    string Title,
    string DefaultResponse,
    int XPos,
    int YPos
)
Visual C++
[HostProtectionAttribute(SecurityAction::LinkDemand, Resources = HostProtectionResource::UI)]
public:
static String^ InputBox(
    String^ Prompt, 
    String^ Title, 
    String^ DefaultResponse, 
    int XPos, 
    int YPos
)
JScript
public static function InputBox(
    Prompt : String, 
    Title : String, 
    DefaultResponse : String, 
    XPos : int, 
    YPos : int
) : String

Parameters

Prompt
Type: System..::.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
Type: System..::.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
Type: System..::.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
Type: System..::.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
Type: System..::.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.

Return Value

Type: System..::.String
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.
NoteNote:

The HostProtectionAttribute attribute applied to this type or member has the following Resources property value: Resources. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

For more detailed information, see the Visual Basic topic InputBox Function (Visual Basic).

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.

NoteNote:

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.

Visual Basic
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

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker