InputBox, InputBox$ Functions

See Also0YWKBL              Example93QGJ>Low

Displays a prompt in a dialog box, wait for the user to input text or choose a button, and returns the contents of the text box.

Syntax

InputBox[$](prompt [, [title] [, [default][, xpos, ypos ] ] ])

Remarks

InputBox returns a Variant8PHEAW3 of Vartype7A68ZTZ 8 (String); InputBox$ returns a String.

The InputBox[$] function has these parts:

Part               Description

 

prompt           String expression1330R89 displayed as the message in the dialog box.  The maximum length of prompt is approximately 255 characters depending on the width of the characters used.  If prompt will consist of more than one line, be sure to include a carriage return (ANSI5221FB character 13) and a linefeed (ANSI character 10) between each line.

title                String expression displayed in the title bar32N908X of the dialog box.  If you omit the title, nothing is placed in the title bar.

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

xpos              Numeric expression71RISN that specifies, in twips2SWJ8D3, the horizontal distance of the left edge of the dialog box from the left edge of the screen.  If you omit xpos, you must also omit ypos.  If xpos and ypos are omitted, the dialog box is horizontally centered and vertically positioned approximately one third of the way down the screen.  If you omit either title or default or both but include xpos and ypos, you must still include the commas that separate the arguments.

ypos              Numeric expression that specifies, in twips, the vertical distance of the upper edge of the dialog box from the top of the screen.

If the user chooses the OK button or presses Enter, the InputBox[$] function returns whatever is in the text box.  If the user chooses the Cancel button, the function returns a zero-length string ("").


See Also

MsgBox Function, MsgBox StatementZKF8GC


InputBox, InputBox$ Function Example

The example prompts the user with a message and returns the user-entered value.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Sub Form_Click ()

   Dim Answer, DefVal, Msg, Title           ' Declare variables.

   Msg = "Enter a value from 1 to 3."       ' Set prompt.

   Title = "InputBox Demo"                  ' Set title.

   DefVal = "1"                             ' Set default return value.

   Do

      Answer = InputBox(Msg, Title, DefVal) ' Get user input.

   Loop Until Answer >= 1 And Answer <= 3

   MsgBox "You entered " & Answer           ' Display message.

End Sub