VBS, a subset of Visual Basic, allows you to create Web-based and desktop applications quickly. Although VBS has no user interface controls, it can still display HTML buttons, labels and even menus when used with HTA. HTA, short for HTML Applications, serves as a wrapper for VBS. Using these technologies together, you can add useful menus and other controls to your VBS applications.
- Skill level:
- Moderately Easy
Other People Are Reading
Open Notepad and paste the following code into a new document:
<HTA:APPLICATION ID="vbsMenu" APPLICATIONNAME="VBS Menu">
<select size="1" name="Menu1" onChange="ShowSelectedValue">
<option value="0">Select a value/option> <option value="1">Value 1</option> <option value="2">Value 2</option> <option value="3">Value 3</option> <option value="4">Value 4</option>
This creates a basic HTA document named "VBS Menu." The code between the "<body>" tags adds a drop-down menu containing five values.
Add the following code after the "</head>" tag:
menu Items = Window.Menu1.SelectedIndex selected Text = Window.Menu1.Options(menuItems).Text
MsgBox selected Text
This adds a VBS subroutine that runs when you select a menu item. This code stores the index of the item that you choose in "menuItems." For instance, if you choose item two from the menu, "menuItems" will have a value of "2." The "selectedText" variable holds the text value of the selected menu item.
Click "File" and select "Save As" to open Notepad's "Save As" window.
Type "My_VBS_Menu_Test.hta" in the "File Name" box and click "Save." This will save the document as an HTA application.
Open Windows Explorer and navigate to the folder containing the file that you saved. Double-click the file. A window will open and display the VBS menu.
Click the drop-down arrow and select an item. The code will execute and display the value that you select.
Tips and warnings
- In this simple example, the VBS subroutine simply displays the selected menu item. You can perform tasks that are more useful by examining the selected menu item's value and executing other functions. For instance, if you create a menu containing file names, you might open a file, depending on the value that a user selects from the VBS menu.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for