Code Examples
  Home arrow Code Examples arrow Page 4 - Creating a Custom Object with WSC
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
CODE EXAMPLES

Creating a Custom Object with WSC
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2009-03-30

    Table of Contents:
  • Creating a Custom Object with WSC
  • Using the Script Component Wizard
  • Creating the Public Interface
  • Wrapping up the wizard

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a Custom Object with WSC - Wrapping up the wizard


    (Page 4 of 4 )

    In step five of the component wizard you’re given an opportunity to add events to your component.  The ZipFolder component does not have any events, so I simply skipped that step and moved on to the last one, where you’re asked to confirm your actions.  Pressing Finish on this screen will output a WSC file to the directory you specified in the first step.

    <?xml version="1.0" ?>

    The first line defines the document type as an XML file.  This will cause the XML parser to validate your WSC file before it is loaded by the script host.  You can omit this line if you choose, but I recommend leaving it in place.  Future releases may not be so relaxed about improperly formatted XML files.

    <package>

       <component id="ZipFolder">

           <?component error="false" debug="false" ?>

          <registration

              progid="ZipFolder.WSC"

              classid="{22b7a277-1736-4889-801c-8f240fdf1f3a}"

              description="ZipFolder"

              remotable="no"

              version="1.00">

           </registration>

    The entire WSC file is wrapped inside of an optional <package> element.  If your WSC file contains more than one component, you should leave this element in place.

    Next, a <component> element identifies and encapsulates your component.  The name is irrelevant in most cases as it’s only used internally when more than one component is provided.  It’s good practice to provide an id nonetheless.

    You should recognize the information in the <registration> section.  Its attributes contain the information you provided in the first step of the wizard, including the description, ProgID, and version number for your component.  All of these items are optional, but you’ll need to provide at minimum a ClassID if you intend to register your component.  It’s a good idea to provide a friendly ProgID as well, otherwise you’ll have to remember that ClassID!

           <public>

              <property name="FullName">

                  <get/>

                  <put/>

              </property>

              <property name="Path">

                  <get/>

              </property>

              <property name="Count">

                  <get/>

              </property>

              <property name="Name">

                  <get/>

              </property>

              <method name="Open">

                  <parameter name="strFile"/>

              </method>

              <method name="Create">

                  <parameter name="strFile"/>

              </method>

              <method name="Add">

                  <parameter name="strFile"/>

                  <parameter name="blnKeepOriginal"/>

              </method>

              <method name="AddMultiple">

                  <parameter name="varSource"/>

                  <parameter name="blnKeepOriginal"/>

              </method>

              <method name="Extract">

                  <parameter name="strFolder"/>

              </method>

           </public>

    The <public> element defines your object’s public interface.  These are the properties and methods that you want to be available when using your object in other scripts.  Only those properties and methods listed here will be exposed through your object.

           <script language="VBScript">

    <![CDATA[

     

    ]]>

           </script>

       </component>

    </package>

    Finally, the <script> element provides a place for you to put your object’s code.  It’s good practice to specify the language attribute, but the scripting engine is generally smart enough to figure it out if you do not.  You can add as many <script> elements as you like, so you’re not limited to a single language!  You can also mix and match any compatible languages.

    I’m out of space once again.  In my next article we’ll finish creating our own custom object.  I'll show you the code required for the ZipFolder object, teach you some extras features you can use in your own components, and show you how to protect the source code in your components if you choose to distribute them.  Until next time, keep coding!

    You can download a working example of this component here.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    CODE EXAMPLES ARTICLES

    - Bipartite Graphs
    - Connectivity in Graphs
    - The Ford-Fulkerson Algorithm
    - Critical Paths
    - The Bellman-Ford and Roy-Floyd Algorithms
    - Shortest Path Algorithms in Graphs
    - Minimum Spanning Tree
    - Articulation Edges and Vertexes
    - Circles and Connectivity in Graphs
    - Depth-First Search in Graphs
    - Breadth-First Search in Graphs
    - The Prufer Code and the Floyd-Warshall Algor...
    - An Insight into Graphs
    - Coding a Custom Object with WSC
    - Creating a Custom Object with WSC





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek