Example #2: Using the Script Wizard

In this example, you will use the Script Wizard to modify the code you wrote in Example #1. You will add some button controls to the page to allow the user to manually change the chart style. You will use the Script Wizard to map the OnClick events of the buttons to the ChartType property of the chart.

Step 1

Create a folder named example2 in a convenient location on your computer.

Figure 9-9.

A sample of the Script Wizard in code view.

Step 2

Open the bar.htm file you created in Example #1 in ActiveX Control Pad. Select Save As from the File menu, and save the file as barpie.htm in the example2 folder you just created. Add two intrinsic buttons to frmTest by placing the following code in the HTML Source Editor just before the </FORM> tag:

<P><INPUT TYPE=BUTTON VALUE="Bar Chart" NAME="cmdBar">
<P><INPUT TYPE=BUTTON VALUE="Pie Chart" NAME="cmdPie"> 

Step 3

Start the Script Wizard by selecting Script Wizard from the Tools menu. The Script Wizard should appear. Make sure the wizard is in list view.

Step 4

In the event pane, double-click on the frmTest object to find the cmdBar button object. Double-click on the cmdBar object to reveal the OnClick event. Single-click on the OnClick event to select it.

Step 5

In the action pane, double-click on the frmTest object to find the chtTest object. Double-click on the chtTest object to reveal the ChartType property.

Step 6

Double-click on the ChartType property. A ChartType property dialog box is displayed. Figure 9-10 shows the ChartType property dialog box.

Figure 9-10.

The ChartType property dialog box.

In the dialog box, select 14 - Simple Bar Chart and click OK. The script pane of the Script Wizard displays the results as shown in Figure 9-11.

Figure 9-11.

The Script Wizard in list view after a cmdBar OnClick action has been added.

Step 7

Switch to code view by selecting the appropriate radio button in the Script Wizard. In code view, you can see the equivalent VBScript code for the actions you specified. Figure 9-12 shows the Script Wizard in code view.

Figure 9-12.

The Script Wizard in code view after a cmdBar OnClick action has been added.

Click the OK button to insert this code into your HTML document. The Script Wizard modifies the code for the cmdBar <INPUT> tag in the following way:

<INPUT LANGUAGE="VBSEcript" TYPE=BUTTON VALUE="Bar Chart" ONCLICK="chtTest.ChartType = 14" NAME="cmdBar"> 

Step 8

Repeat steps 3 through 7, replacing references to the cmdBar button with references to the cmdPie button. In step 6, select 1 - Special Pie Chart in the ChartType property dialog box.

Step 9

Save the page, and open it in the Internet Explorer. You should be able to change the chart type by clicking each of the buttons on the page. Figure 9-13 (page 358) shows how the page looks in the Internet Explorer.

Figure 9-13.

Barpie.htm after button controls and VBScript code generated with the Script Wizard have been added.

© 1996 by Scot Hillier. All rights reserved.