InputBox - VBScript


Overview

The InputBox command prompts the user for input via a modal dialog box. It is commonly used to collect user-defined values or provide options for the script.

Syntax

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

Parameters:

  • prompt: Required string specifying the text to display in the input box.
  • title: Optional string setting the title of the input box window. Defaults to “Input”.
  • default: Optional string containing the default value to display in the input box. Defaults to an empty string.
  • xpos: Optional integer specifying the horizontal position of the input box window in pixels from the left edge of the screen. Defaults to the center of the screen.
  • ypos: Optional integer specifying the vertical position of the input box window in pixels from the top edge of the screen. Defaults to the center of the screen.

Options/Flags

  • None

Examples

Simple Usage:

userName = InputBox("Enter your name:")

Complex Usage (with title, default value, and position):

input = InputBox("Provide a value (default: 10):", "Input Box", 10, 200, 100)

Common Issues

  • Blank Input: If the user leaves the input box empty and clicks “OK”, an empty string will be returned. Use error checking to handle this case.
  • Modal Dialog Timeout: The input box is a modal dialog, so it blocks other actions in the script until it is closed. Use a timer to set a timeout if necessary.

Integration

Chaining with WScript.Echo:

WScript.Echo InputBox("Enter a message to display:")

Using with Select Case:

input = InputBox("Select an option:")
Select Case input
    Case "1":
        ' Code for option 1
    Case "2":
        ' Code for option 2
    Case Else
        ' Code for default
End Select
  • MsgBox: Displays a message box with predefined buttons (e.g., OK, Cancel).
  • Input: Waits for user input in the console window.