Controlling Objects with VBScript

Writing Event Procedures

In this exercise, you will write VBScript code to calculate the total cost of items selected in the Product table.

You will add functionality to the Product List Web page, Products.htm . Use the page provided in the WA\Practice\Ch09 directory.

* To add SCRIPT tags to the products Web page

  1. Start Microsoft FrontPage 98.
  2. Create a new Empty Web named Lab09 .
  3. From the File menu, click Import .
  4. Click Add File and select Lab09.htm located in the WA\Practice\Ch09 folder, then click OK .
  5. Double-click Lab09.htm to open the file in the FrontPage Editor.
  6. Place the insertion point to the right of the Calculate button.
  7. From the Insert menu, point to Advanced and then click Script .
  8. Enter the following script and click OK .
     Function TotalIt() Dim price On Error Resume Next price = txtQ1.Text * 2.99 price = price + txtQ2.Text * 75.59 price = price + txtQ3.Text * 1.75 price = price + txtQ4.Text * 7.99 price = price + txtQ5.Text * 4.99 TotalIt = price End Function 
* To use the Script Wizard
  1. Right-click Calculate and click Script Wizard .
  2. Select Code View at the bottom of the dialog window.
  3. In the frmButtonContainer , CalcTotal_OnClick event, type the following event procedure:
     lblTotal.Caption = TotalIt() 
  4. Click OK to close the Script Wizard.
  5. Save your changes.
  6. From the toolbar, click Preview in Browser .
  7. Type some values into the quantity text boxes and click Calculate .

    The spin controls do not have script yet, so you must enter the values manually.

* To add an event procedure for the spin controls
  1. Switch to the FrontPage Editor.
  2. Right-click on the spin control in the top, right corner of the Web page.
  3. Click Script Wizard .
  4. In the spin1_SpinUp event, type the following code:
     txtq1.text = txtq1.text + 1 
  5. For the spin1_SpinDown event for the spin control, type the following code:
     If txtq1.text > 0 Then txtq1.text = txtq1.text - 1 
  6. Repeat Steps 2-4 for each spin button on the Web page. Modify the text box control names accordingly . (IE. txtq2, txtq3, txtq4, etc).
  7. Save your Web page.
  8. From the toolbar, click Preview In Browser .

    You may need to click Refresh to reload the page.

  9. Type in some values for the quantity and use the spin buttons to modify the values.


Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net