Library tutorials & articles

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
%>

Comments

  1. 22 Feb 2004 at 23:46
    In an interview, they asked me what are the components of ASP and VB. Can any body help me?.
  2. 17 Jul 2002 at 08:02

    If you want to try using components, start using those allready installed on your server. Use this script to check your IIS for installed components:
    http://www.bier-voting.de/objcheck/
     

  3. 01 Jan 1999 at 00:00

    This thread is for discussions of Using Components and Objects in ASP.

Leave a comment

Sign in or Join us (it's free).

Talal Ahmed Siddiqui

We'd love to hear what you think! Submit ideas or give us feedback