Using Components and Objects in ASP

Creating COM components

ASP supports Windows Script Components, Microsoft's powerful scripting technology that you can use to create COM components. Specifically, you can encapsulate common scripts, such as those used for database access or content generation, into reusable components accessible from any .asp file or program. You can create Windows Script Components by writing scripts in a language such as VBScript or JScript without a special development tool. You can also incorporate Windows Script Components into programs written in COM compliant programming languages, such as Visual Basic, C++, or Java. The following is an example of a Windows Script Components, written in VBScript, that defines methods for converting temperature measurements between Fahrenheit and Celsius:

<SCRIPTLET>

<Registration
Description="ConvertTemp"
ProgID="ConvertTemp.Scriptlet"
Version="1.00"
>
</Registration>

<implements id=Automation type=Automation>
<method name=Celsius>
<PARAMETER name=F/>
</method>
<method name=Fahrenheit>
<PARAMETER name=C/>
</method>
</implements>

<SCRIPT LANGUAGE=VBScript>

Function Celsius(F)
    Celsius = 5/9 * (F - 32)
End Function

Function Fahrenheit(C)
    Fahrenheit = (9/5 * C) + 32
End Function

</SCRIPT>
</SCRIPTLET>

Before implementing this Windows Script Component you must save this file with an .sct extension and then in Windows Explorer, right-click this file and select Register. To use this Windows Script Component in a Web page, you would use a server-side script such as the following:

<%
Option Explicit

Dim objConvert
Dim sngFvalue, sngCvalue

sngFvalue = 50
sngCvalue = 21

Set objConvert = Server.CreateObject("ConvertTemp.Scriptlet")

Response.Write sngFvalue & " degrees Fahrenheit is equivalent to " & objConvert.Celsius(sngFvalue) & " degrees Celsius<br>" & vbNewLine
Response.Write sngCvalue & " degrees Celsius is equivalent to " & objConvert.Fahrenheit(sngCvalue) & " degrees Fahrenheit<br>" & vbNewLine
%>

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.”