Understanding Windows Script Components, Part 4By David Power
In Part 3 we looked at the properties and methods for the
dpCoolBox WSC component. In this final part we'll examine the actual code and wrap things up!
The Component Code
We won't analyze every line of code here... just the more important ones. In fact, if you use the WSC Wizard to create your own component, the Wizard actually does much of the work for you including:
- Creating all the necessary XML tags
- Generating a unique Class ID
- Assigning default values you specify to the component's properties
- Creating functions for both reading and writing property values
- Creating function shells for the component's methods
Practically the only thing the Wizard won't do is create the component's functionality for you. Oh well...
maybe in the next release!
Since the Wizard does practically all of the administrative work for you, we won't analyze any of the
automatically generated code. Instead we'll focus on the code comprising the component's core functionality...
The component was developed in JScript but even if you happen to be a VBScript junkie, you should have no
difficulty following along.
First of all, the
As you can see this method doesn't perform processing or calculations of any kind. It simply takes the
boilerplate HTML for the
dpCoolBox, populates it with property values and returns it as a text
The code for
setDefault() is simpler still. When called, this method sets all of the component's
properties to predefined values.
Note: If you decide to use this component in your own projects, feel free to change the default values
to any you find useful. However, be aware that in addition to changing defaults in the
method, you'll also need to change them immediately below the code for the
dpCoolBox function. If
you browse through the component code (supplied in this article's support material), this should become clear to
At this point you'll hopefully agree that Windows Script Components can be an extremely powerful addition to your ASP arsenal. If this article has accomplished what it set out to do... you're already considering transforming some of your existing utility functions into WSC's.
Let's recap some of the more noteworthy advantages of Windows Script Components:
1) For complex functions, WSC's are more efficient than server-side includes.
2) The object-oriented features of WSC's make coding far less cumbersome for functions which require many arguments.
3) WSC's can be instantiated without being registered on the server.
4) WSC's are COM compliant and can be instantiated from within other development environments including VisualBasic and C++.
These advantages, in addition to the ease with which they can be created and their versatility, make WSC's an attractive technology for use in many small to mid-sized projects. Even for large scale projects, WSC's provide developers with an extremely powerful prototyping tool!
In order to get the most benefit out of this article, I strongly recommend following these steps:
1) Write some test scripts to get familiar with using the
dpCoolBoxcomponent in its current form.
2) Try modifying the component to get comfortable with its inner workings (ex. try setting your own default values, add error checking or an additional method or two).
3) Download the Script Component Wizard from Microsoft and create your own component.
By the time you've completed the third step... you'll be well on your way to becoming a WSC guru. Best of luck!
By David Power
David Power is President of Power Internet Technologies Inc., an Internet consulting firm in Toronto, Canada. David has a degree in Electrical Engineering and is also a Chartered Financial Analyst.
Power Internet Technologies Inc. specializes in the design and development of interactive web applications and has resident expertise in the areas of finance, securities trading, real estate and event planning.
David can be reached at: firstname.lastname@example.org