This chapter describes a sample Web application created using VBScript. The example is
Example 1. XYZ Inc. Corporate Intranet
Document title: XYZ Corporate Intranet
Files:
Page files:
Images:
ActiveX controls used:
Description: This example shows how to implement an ActiveX menu control. To aid maintenance and to speed the addition of further menu items, the text for each menu item and the associated location for each menu item are held within arrays, which are transferred to the menu at runtime. The other method of populating a menu is to specify a menu item as a parameter, <PARAM MenuItem[1]... >, within the <OBJECT> tag. However, the maintenance of these menus can become somewhat confusing when there are a large number of menus and menu items.
The maintenance of the locations that are loaded when a menu item is clicked is also enhanced because the locations are held within arrays, which are specified at the beginning of the script.
The example also demonstrates how to implement a continuous clock within the menu bar, using an ActiveX label and an ActiveX timer control.
The menu bar is displayed within the upper frame of a borderless frameset. The lower frame is used to display the content pages for the Web site.
ActiveX controls: (See Chapters 1, 12, 13, and 14.) The example uses a range of ActiveX controls. The example also demonstrates changing properties at runtime-in this case, to populate the menus.
Arrays: (See Chapter 10, "Using the Power of Arrays.") The menu items and the locations, which are loaded when you click a menu item, are held within multidimensional static arrays.
Programming elements: (See Chapter 9 "Making Your Program Flow.") A range of VBScript language elements are used.
The example uses a frameset document (menudemo.htm), which creates an upper frame into which the menu document is loaded (menu.htm) and a lower frame that contains the main pages, as shown in Figure 23.1.
Figure 23.1 : The menu bar and opening page.
When the user clicks on a menu item, the particular menu pops up, as shown in Figures 23.2 and 23.3.
Figure 23.3 : The Customers menu.
Clicking on a menu item causes the page associated with that menu item to be loaded in the lower frame, as shown in Figure 23.4.
Figure 23.4 : One of the Web pages loaded into the lower frame.
A timer control is used to display a clock at the end of the menu bar. At predetermined intervals, the timer event (shown in Figure 23.5) is fired, causing the clock display to be updated.
Figure 23.5 : The script to operate the clock.
As the application is loading, the OnLoad event handler (shown in Figure 23.6) creates the menus from the data stored in the arrays.
Figure 23.6 : The onLoad event handler.
The menu's Click event, shown in Figure 23.7, loads the required page into the lower frame. The value of the menu caption is passed to a form and is used in this example to display the correct caption on the page (b.htm) in the lower frame.
Figure 23.7 : The menu's Click event handler.
The menu objects are defined within the HTML code. They are shown in the ActiveX Control Pad in Figure 23.8.
Figure 23.8 : The menu object definitions.
Listing 23.1 shows the HTML code for the frameset document menudemo.htm.
Listing 23.1. The menudemo.htm code.
<HTML> <HEAD> <TITLE>XYZ Inc. Intranet</TITLE> </HEAD> <FRAMESET ROWS=8%,92% FRAMEBORDER=0 FRAMESPACING=0> <FRAME SRC="menu.htm" NAME="menubar" MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING=No NORESIZE> <FRAME SRC="welcome.htm" NAME="mainbody"> </FRAMESET> </HTML>
Listing 23.2 shows the complete source code for the menu document, menu.htm.
Listing 23.2. The menu.htm code.
<HTML> <HEAD> <TITLE>New Page</TITLE> <SCRIPT LANGUAGE="vbscript"> <!-- Dim NewPage Dim MenuItems(6,10) Dim MenuLocations(6,10) Dim MaxItems(6) Dim FILE_MENU, CUST_MENU, PROD_MENU, USERS_MENU, EXTERNAL_MENU, HELP_MENU FILE_MENU = 0 CUST_MENU = 1 PROD_MENU = 2 USERS_MENU = 3 EXTERNAL_MENU = 4 HELP_MENU = 5 MenuItems(FILE_MENU,1) = "Welcome Page" MenuItems(FILE_MENU,2) = "Latest Company News" MenuItems(FILE_MENU,3) = "New and Updated Areas" MenuLocations(FILE_MENU,1) = "welcome.htm" MenuLocations(FILE_MENU,2) = "b.htm" MenuLocations(FILE_MENU,3) = "b.htm" MaxItems(FILE_MENU) = 3 MenuItems(CUST_MENU,1) = "Search Customer Database" MenuItems(CUST_MENU ,2) = "Browse Customer Database" MenuItems(CUST_MENU ,3) = "Add New Customer Record" MenuItems(CUST_MENU ,4) = "Edit Customer Record" MenuLocations(CUST_MENU ,1) = "b.htm" MenuLocations(CUST_MENU ,2) = "b.htm" MenuLocations(CUST_MENU ,3) = "b.htm" MenuLocations(CUST_MENU ,4) = "b.htm" MaxItems(CUST_MENU) = 4 MenuItems(PROD_MENU,1) = "Search Product Database" MenuItems(PROD_MENU,2) = "Browse Product Database" MenuItems(PROD_MENU,3) = "Add New Product Record" MenuItems(PROD_MENU,4) = "View Product Technical Reports" MenuItems(PROD_MENU,5) = "Add Product Comment" MenuLocations(PROD_MENU,1) = "b.htm" MenuLocations(PROD_MENU,2) = "b.htm" MenuLocations(PROD_MENU,3) = "b.htm" MenuLocations(PROD_MENU,4) = "b.htm" MenuLocations(PROD_MENU,5) = "b.htm" MaxItems(PROD_MENU) = 5 MenuItems(USERS_MENU,1) = "Search User Database" MenuItems(USERS_MENU,2) = "User EMail Addresses" MenuItems(USERS_MENU,3) = "Change your password" MenuItems(USERS_MENU,4) = "Employee Forum" MenuItems(USERS_MENU,5) = "Technical Forum" MenuLocations(USERS_MENU,1) = "b.htm" MenuLocations(USERS_MENU,2) = "b.htm" MenuLocations(USERS_MENU,3) = "b.htm" MenuLocations(USERS_MENU,4) = "b.htm" MenuLocations(USERS_MENU,5) = "b.htm" MaxItems(USERS_MENU) = 5 MenuItems(EXTERNAL_MENU,1) = "Microsoft" MenuItems(EXTERNAL_MENU,2) = "SAMS.Net" MenuItems(EXTERNAL_MENU,3) = "vbscripts.com" MenuLocations(EXTERNAL_MENU,1) = "http://www.microsoft.com/" MenuLocations(EXTERNAL_MENU,3) = "http://www.vbscripts.com/" MaxItems(EXTERNAL_MENU) = 3 MenuItems(HELP_MENU,1) = "Search Help Topics" MenuItems(HELP_MENU,2) = "Contact Support Desk" MenuItems(HELP_MENU,3) = "Contact Support Desk" MenuLocations(HELP_MENU,1) = "b.htm" MenuLocations(HELP_MENU,2) = "b.htm" MenuLocations(HELP_MENU,3) = "b.htm" MaxItems(HELP_MENU) = 3 Sub window_onLoad() For i = 1 to MaxItems(FILE_MENU) call FileMenu.AddItem(MenuItems(FILE_MENU,i), i) Next For i = 1 to MaxItems(CUST_MENU) call CustomerMenu.AddItem(MenuItems(CUST_MENU,i), i) Next For i = 1 to MaxItems(PROD_MENU) call ProductMenu.AddItem(MenuItems(PROD_MENU,i), i) Next For i = 1 to MaxItems(USERS_MENU) call UsersMenu.AddItem(MenuItems(USERS_MENU,i), i) Next For i = 1 to MaxItems(EXTERNAL_MENU) call ExternalMenu.AddItem(MenuItems(EXTERNAL_MENU,i), i) Next For i = 1 to MaxItems(HELP_MENU) call HelpMenu.AddItem(MenuItems(HELP_MENU,i), i) Next End sub Sub File_OnClick FileMenu.PopUp End Sub Sub Customers_OnClick CustomerMenu.PopUp End Sub Sub Products_OnClick ProductMenu.PopUp End Sub Sub Users_OnClick UsersMenu.PopUp End Sub Sub External_OnClick ExternalMenu.PopUp End Sub Sub Help_OnClick HelpMenu.PopUp End Sub Sub FileMenu_Click(ByVal item) Parent.mainbody.Location.hRef = MenuLocations(FILE_MENU, item) Document.Form1.NewPage.Value = MenuItems(FILE_MENU, item) end sub Sub CustomerMenu_Click(item) Parent.mainbody.Location.hRef = MenuLocations(CUST_MENU, item) Document.Form1.NewPage.Value = MenuItems(CUST_MENU, item) end sub Sub ProductMenu_Click(item) Parent.mainbody.Location.hRef = MenuLocations(PROD_MENU, item) Document.Form1.NewPage.Value = MenuItems(PROD_MENU, item) end sub Sub UsersMenu_Click(item) Parent.mainbody.Location.hRef = MenuLocations(USERS_MENU, item) Document.Form1.NewPage.Value = MenuItems(USERS_MENU, item) end sub Sub ExternalMenu_Click(ByVal item) top.Location.hRef = MenuLocations(EXTERNAL_MENU, item) end sub Sub HelpMenu_Click(item) Parent.mainbody.Location.hRef = MenuLocations(HELP_MENU, item) Document.Form1.NewPage.Value = MenuItems(HELP_MENU, item) end sub --> </SCRIPT> </HEAD> <BODY BGCOLOR="white"> <CENTER> <IMG SRC="leftend.gif"> <A HREF="menu.htm" ID="File"><IMG SRC="file.gif" BORDER=0></A> <A HREF="menu.htm" ID="Customers"><IMG SRC="cust.gif" BORDER=0></A> <A HREF="menu.htm" ID="Products"><IMG SRC="prod.gif" BORDER=0></A> <A HREF="menu.htm" ID="Users"><IMG SRC="users.gif" BORDER=0></A> <A HREF="menu.htm" ID="External"><IMG SRC="external.gif" BORDER=0></A> <A HREF="menu.htm" ID="Help"><IMG SRC="help.gif" BORDER=0></A> <OBJECT ID="TimeLabel" WIDTH=95 HEIGHT=22 CLASSID="CLSID:978C9E23-D4B0-11CE-Bf2D-00AA003f40D0"> <PARAM NAME="BackColor" VALUE="15066597"> <PARAM NAME="VariousPropertyBits" VALUE="268435483"> <PARAM NAME="Caption" VALUE="Current Time:"> <PARAM NAME="Size" VALUE="2505;529"> <PARAM NAME="BorderColor" VALUE="16711680"> <PARAM NAME="BorderStyle" VALUE="1"> <PARAM NAME="FontEffects" VALUE="1073741825"> <PARAM NAME="FontHeight" VALUE="200"> <PARAM NAME="FontCharSet" VALUE="0"> <PARAM NAME="FontPitchAndFamily" VALUE="2"> <PARAM NAME="FontWeight" VALUE="700"> </OBJECT> <IMG SRC="rightend.gif"><BR> <FORM NAME="form1"> <INPUT TYPE=hidden NAME="NewPage"> </FORM> <SCRIPT LANGUAGE="vbscript"> <!-- Sub IeTimer1_Timer() TimeLabel.Caption = "Current Time: " & Time() end sub --> </SCRIPT> <OBJECT ID="IeTimer1" WIDTH=19 HEIGHT=19 CLASSID="CLSID:59ccB4A0-727D-11CF-AC36-00AA00A47DD2"> <PARAM NAME="_ExtentX" VALUE="503"> <PARAM NAME="_ExtentY" VALUE="503"> <PARAM NAME="Interval" VALUE="100"> </OBJECT> <OBJECT ID="FileMenu" WIDTH=10 HEIGHT=10 CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2"> </OBJECT> <OBJECT ID="CustomerMenu" WIDTH=10 HEIGHT=10 CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2"> </OBJECT> <OBJECT ID="ProductMenu" WIDTH=10 HEIGHT=10 CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2"> </OBJECT> <OBJECT ID="UsersMenu" WIDTH=10 HEIGHT=10 CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2"> </OBJECT> <OBJECT ID="ExternalMenu" WIDTH=10 HEIGHT=10 CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2"> </OBJECT> <OBJECT ID="HelpMenu" WIDTH=10 HEIGHT=10 CLASSID="CLSID:7823A620-9DD9-11CF-A662-00AA00C066D2"> </OBJECT> </CENTER> </BODY> </HTML>