Computers & ProgrammingComputers & NetworkingVBScript

Creating a Pop-up Message using VBScript

The Popup method produces a pop-up message box that can display a message to a user for a specified amount of time. If the message time is omitted or set to zero, the pop-up will remain until the user dismisses the message.

In addition, a title can be assigned to the pop-up message. If it is omitted, the default is “Windows Script Host”. The syntax is as follows:

WshShell.Popup strText[,nSecondsToWait] [,strTitle] [,nType]

Arguments:

  • strText – String value containing the text you want to appear in the pop-up message box.
  • nSecondsToWait – Optional. Numeric value indicating the maximum length of time (in seconds) you want the pop-up message box displayed.
  • strTitle – Optional. String value containing the text you want to appear as the title of the pop-up message box.
  • nType – Optional. Numeric value indicates the type of buttons and icons you want in the pop-up message box. These determine how the message box is used.
  • IntButton – Integer value indicates the number of buttons the user clicked to dismiss the message box. This is the value returned by the Popup method

Button Types:

  • 0 – Show OK button
  • 1 – Show OK and Cancel buttons
  • 2 – Show Abort, Retry, and Ignore buttons
  • 3 – Show Yes, No, and Cancel buttons
  • 4 – Show Yes and No buttons
  • 5 – Show Retry and Cancel buttons

Icons:

  • 16 – Show “Stop Mark” icon
  • 32 – Show “Question Mark” icon
  • 48 – Show “Exclamation Mark” icon
  • 64 – Show “Information Mark” icon

intButton Return Codes:

  • 1 – OK button
  • 2 – Cancel button
  • 3 – Abort button
  • 4 – Retry button
  • 5 – Ignore button
  • 6 – Yes button
  • 7 – No button

If the user does not click a button before nSecondsToWait seconds, intButton is set to -1.

Example:

Dim WshShell, BtnCode
Set WshShell = WScript.CreateObject("WScript.Shell")
BtnCode = WshShell.Popup("Do you like your job?", 7, "Answer This Question:", 4 + 32)
Select Case BtnCodecase 6 WScript.Echo "That's great!."
case 7 WScript.Echo "Sorry to hear that."
case -1 WScript.Echo "No Response?"
End Select

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top