In Part 1 and Part 2 we looked at how to create a Windows Script Component skeleton using the Wizard. In this part, we'll look at adding the source code to our "skeleton" component and registering the component. Finally, we'll look at how to use our newly created component in an ASP page!
Take a moment to look at the source for the Temperature.wsc file we just
created. Note the XML-format of the component. The part we are interested in is the
actual source code, which is located between the <SCRIPT LANGUAGE="VBScript">
and </SCRIPT> tags. Note that our two functions contain just an empty
body. It is up to us to write this code. Go ahead and enter the following code:
|
Now, we're ready to register our component! This is very easy to do, no more
regsvr32! Simply right-click on the .wsc file and select
Register. It's that easy!
Now that the component is registered you can use it like any other COM component! From
an ASP page, instantiate the object using Server.CreateObject("Temperature.Convert").
Here is some sample code using the new COM object:
|
The output of the above script is: 49 degrees Fahrenheit is 9.44444444444444 degrees. 28.5 degrees Celcius is 83.3 degrees.
So there you have Windows Script Components! Note that if you wanted to alter this component
at all, you would only need to edit the .wsc file! You wouldn't need to bother
stopping/starting the Web server or reregistering the component! Personally I find
Windows Script Components to be very cool, very powerful, and very useful.
From Alert 4Guys Reader Matt J.
Keep in mind that WSC components are
Apartment threaded, so using them anywhere but at page scope is evil. (Of
course, using object at Session or Application scope might also be
evil, but
they can at least perform well if they are Both threaded and aggregate the
Free-Threaded Marshaler.)
Happy Programming!



