When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Wednesday, October 18, 2000

Understanding Windows Script Components
By David Power


Introduction
Back in May 2000, 4Guys resident ASP guru Scott Mitchell contributed an article entitled Building Windows Script Components. The article provided an overview of the uses of COM components within ASP, a description of Windows Script Components (i.e. WSC's), their benefits over compiled components and a detailed walk through of the WSC Wizard which can be downloaded without charge from Microsoft.com. If you haven't read this article, I highly recommend reading it now!

- continued -

Today, we'll build upon the framework laid in this previous article by analyzing the advantages of WSC's a little more closely and, later in the article, creating our own script component.... one you'll surely find many uses for!

COM Objects - General
Most seasoned ASP veterans have used some form of COM component at some point in time. (For those new to creating COM components, I highly recommend the following article: Writing a COM Component with VisualBasic!) The procedure for using a COM component is pretty straight forward:

    1) Instantiate the component:

    var objComp = new ActiveXObject("NameOf.Component"); // in JScript

    or

    Set objComp = Server.CreateObject("NameOf.Component") ' in VBScript

    2) Set any necessary properties:

    objComp.width = 600; // set the width to 600 pixels
    objComp.color = "FF0000"; // set the color to red

    3) Call the method you wish to execute:

    objComp.draw(); // draw the chart

The beauty of WSC's is that they are in fact COM objects and as such they are instantiated and utilized in a manner identical to objects which exist as compiled DLL's. Again, for information on creating WSCs, be sure you do read Scott's earlier article!

Advantages of WSC's Over Server-Side Includes
If you've done any degree of ASP coding, chances are, you've accumulated a handy toolbox of utility functions which you use on a regular basis. Rather than copying the source code for a given function into every script which requires it, you package your utilities up into a single file (perhaps called utilities.asp) and #include it at the top of your ASP scripts in the following fashion:

<!-- #include file="includes/utilities.asp" -->

(For more information on server-side includes, be sure to read: The Low-Down on #includes!) When used properly, server-side includes are an extremely useful tool. The downside, of course, is that each and every line of code in an include file is parsed by the appropriate language interpreter (i.e. JScript or VBScript) before the ASP script in which it is #included is executed. As you can well imagine, #including a large utility file in an ASP script when only one or two of its functions are required by the script is not the most efficient use of system resources. In contrast, because they're only instantiated when their functionality is required, WSC's alleviate much of the resource overhead required to parse a server-side include file.

A second advantage of WSC's over server-side includes is that because they are COM compliant, they can be instantiated and used from virtually any COM compliant development environment such as Microsoft VisualBasic, C++, Windows Script Host or the like. (Note: this is true provided the component does not call any of the built-in ASP objects: Response, Request, Server, Session, or Application.) You can even create type libraries for your WSC's which are extremely useful if you plan to use them in another language environment.

To suggest that WSC's can be considered an out-and-out replacement for server-side includes, however, would be more than a little brash. Creating a component which formats an ADO recordset into an HTML table would be an efficient use of this technology. In contrast, a server-side isNum() function (i.e. one which returns a boolean value based on whether or not the passed argument is numeric) is far better suited to server-side inclusion as the overhead involved in creating, instantiating and calling the methods of a component which performed such a simple function would be a terribly inefficient use of resources.

Yet another advantage of WSC's is that the object-oriented features of COM objects quite often make coding less cumbersome for the developer. For example, making a function as generic and re-usable as possible often requires that it possess a large number of arguments. Each time the function is called, the programmer must remember the proper number and order of the arguments. Even if a default value can be coded for a given argument, it's normally necessary to pass a dummy variable (i.e. either a null, empty string, zero, etc.) in the proper order for the function to render predictable results.

Component-izing a complex function obviates these inconveniences. Replacing function arguments with object properties means that:

  • Default values can be coded with great ease
  • Properties can be assigned in any desired order
  • If coded as read/write, property values can be modified by component code and later read back by the calling script
  • One or more properties can be modified and the component's methods called again without starting from scratch

Now that we've compared WSCs to server-side includes, let's examine how WSCs compare to compiled components. We'll tackle this in Part 2!

  • Read Part 2!


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES