When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Wednesday, October 18, 2000

Understanding Windows Script Components, Part 4

By David Power

  • Read Part 1
  • Read Part 2
  • Read Part 3

  • 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!

    - continued -

    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... its methods. 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 create() method:

    function create()
      var box_text = "";
      box_text += "<table bgcolor=#" + this.borderColor + " cellpadding=" + 
                  this.borderWidth + " cellspacing=0 border=0 width=" + 
                  this.boxWidth + ">";
      box_text += "<tr><td><table bgcolor=#FFFFFF cellpadding=3 " +
                  "cellspacing=0 border=0 width=100%>";
      box_text += "<tr><td align=" + this.titleAlign + " bgcolor=#" + 
                  this.titleBgColor + "><font face=" + this.titleFontFace + 
                  " size=" + this.titleFontSize;
      box_text += " color=#" + this.titleFontColor + "><b>" + this.titleText + 
                  "</b></td></tr><tr><td align=" + this.bodyAlign + 
                  " bgcolor=#" + this.bodyBgColor + ">";
      box_text += "<font face=" + this.bodyFontFace + " size=" + 
                  this.bodyFontSize + " color=#" + this.bodyFontColor + 
                  ">" + this.bodyText;
      box_text += "</td></tr></table></td></tr></table>";

    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 string. Next, the setDefault() method:

    function setDefault()
      this.boxWidth = "600";
      this.borderWidth = "1";
      this.titleBgColor = "000000";
      this.borderColor = this.titleBgColor;
      this.titleFontFace = "arial";
      this.titleFontColor = "FFFFFF";
      this.titleFontSize = "2";
      this.titleAlign = "left";
      this.titleText = "{TITLE_TEXT}";
      this.bodyBgColor = "FFFFFF";
      this.bodyFontFace = "arial";
      this.bodyFontColor = "000000";
      this.bodyFontSize = "2";
      this.bodyAlign = "left";
      this.bodyText = "{BODY_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 setDefault() 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 you.

    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 dpCoolBox component 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


  • Download the support files in ZIP format
  • Read Building Windows Script Components

    Author Biography:
    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: david@powerinternet.ca

  • ASP.NET [1.x] [2.0] | ASPFAQs.com | Advertise | Feedback | Author an Article