Tag Archive: Dialog Box

VBS Option Box – Simple VBScript MsgBox / Dialog Box with Options

I needed to create a basic script to execute a user selected routine but needed a simple way to capture the users choice. Like a MsgBox but with multiple options.
Here’s some nice simple code for a VBScript Option Box in case you want to do the same.

First we create a very basic HTML file which will act as the dialog box. (the options and buttons)…

<TITLE>Make a selection</TITLE>
<SCRIPT language="VBScript">

Sub OKClick
If MenuOption(0).Checked Then
ChosenOption.Value = "Option 1"
End If
If MenuOption(1).Checked Then
ChosenOption.Value = "Option 2"
End If
If MenuOption(2).Checked Then
ChosenOption.Value = "Option 3"
End If
End Sub

Sub CancelClick
ChosenOption.Value = "Cancelled"
End Sub

<B>Please select an option:</B><P>
<input type="radio" name="MenuOption" checked="true">Option 1<BR>
<input type="radio" name="MenuOption">Option 2<BR>
<input type="radio" name="MenuOption">Option 3
<input type="Button" value="OK" onClick="OKClick()">
<input type="Button" value="Cancel" onClick="CancelClick()">
<input type="hidden" name="ChosenOption">


The hidden input above is used to store the users chosen option.
The VBScript below, opens the HTML file and loops while waiting for this chosen option value to change.
When this chosen option value changes the VBScript captures this chosen option in a variable so it knows what the user selected.

Set objExplorer = CreateObject("InternetExplorer.Application")

objExplorer.Navigate "file:///C:\Script\option.htm"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Width = 400
objExplorer.Height = 230
objExplorer.Visible = 1

Do While (objExplorer.Document.All.ChosenOption.Value = "")
Wscript.Sleep 250

strSelection = objExplorer.Document.All.ChosenOption.Value


Wscript.Sleep 250

Select Case strSelection
Case "Option 1"
Wscript.Echo "You selected Option 1."
Case "Option 2"
Wscript.Echo "You selected Option 2."
Case "Option 3"
Wscript.Echo "You selected Option 3."
Case "Cancelled"
End Select

Of course, instead of echoing the selected option you would put the code you want to run under each case.

This is a nice flexible solution allowing you to easily add/remove options.

You can do away with the OK button and, in the HTML, add onClick="OKClick()" to the radio button elements, so the user only needs to click once on the option they want.

If this info helps you out, tweet me to say thanks or

Because I’m so nice you can download the VBS and HTML files in this handy VBS Option Box Script Zip(851 bytes)
Note: make sure to put the HTML file in "C:\Script\" to test. (Or change the line in the .VBS file pointing to the location of the HTML file.