|
|
|
|
|
|
|
|
Your Third VBScript ExerciseIn Exercise 3 we modify the web page created in Exercise 2. These modifications will be made so that we can display the results of our calculations not with the MsgBox function, but rather to ActiveX objects that are part of the page. Just follow the step-by-step instructions below to begin learning how to use VBScript with ActiveX. Exercise 3: Working with ObjectsIn this exercise, you will create an HTML document that contains a script that will retrieve data from a web page, perform calculations and output a result back to the web page. Testing the HTML DocumentLoad the file exer3_v1.html into a text editor. This is the HTML component of this exercise already typed in for you. Look over the HTML document. It contains three ActiveX label controls named lblSubtotal, lblTaxes and lblTotalCost. Save the file under a different name. We are going to be modifying this source and wouldn't want to work with the original. Test the file by loading it into Internet Explorer. The result is shown below. I'd have you try out the Calculate Cost button, but you have probably already figured out from the previous two exercises that it doesn't do anything.
As we did in Exercise 2, we will now add a script to provide functionality for the Calculate Cost command button's click event. Adding VBScriptA completed copy of this part of the exercise can be found in the file exer3_v2.html. We're going to modify the document, by adding the scripting lines as shown by the shading below:
Save the file and test it by loading it into Internet Explorer. Enter 100 into the Quantity field and 10 into the Unit Price field. Try out the Calculate Cost button. The result is shown below:
How It WorksExercise 3 was just a modification of Exercise 2. As such, we will focus on how they differ, rather than going over the script line by line again. There were minimal changes involving variable declarations and the defining of constant values. We simply didn't need them in this version, so they were removed.
We won't discuss the method used to calculate the subtotal, taxes and total amount, as it is identical between the two versions. The way results are displayed is different in Example 3. The script has been modified to remove the MsgBox function and in its place we set the caption property of three label controls.
The format used when referencing properties is:
Hopefully, by this point you are starting to get comfortable reading and working with VBScript. The best way to strengthen your knowledge of VBScript is to take some of the examples that we have been working with in the first three lessons and modify them to suit your own needs. SummaryWell that's it for Exercise 3. I know, objects are a pretty hefty topic for a small lesson. What we wanted to do was to give you an exposure to objects and how they can be utilized in VBScript Along the way, you have learned:
Next is a lesson in how you can control your script files using conditional and looping statements.
VBScript Tutorial
Contents· What is VBScript? · How to Use this Tutorial Lesson 1 · Adding VBScript to Web Pages · The <SCRIPT> Tag · Non-Supporting Browsers · Your 1stirst VBScript Exercise Lesson 2 · Working with Variables · Declaring Variables · Scope of Variables · Constants · Arrays · Your 2nd VBScript Exercise Lesson 3 · Objects and VBScript · Adding Objects to Web Pages · Linking VBScript with Objects · Your 3rd VBScript Exercise Lesson 4 · Controlling VBScript Routines · Conditional Statements · Looping Statements · Your 4th VBScript Exercise Lesson 5 · Using VBScript with Forms · Validating Your Forms · Your 5th VBScript Exercise · Summary
|