Code Examples
  Home arrow Code Examples arrow Page 2 - Custom Class Objects in VBScript
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

Custom Class Objects in VBScript
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 3
    2009-03-16

    Table of Contents:
  • Custom Class Objects in VBScript
  • Creating Code Classes in VBScript
  • Adding properties to a class
  • More on adding properties

  • 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


    Custom Class Objects in VBScript - Creating Code Classes in VBScript


    (Page 2 of 4 )

    Before we begin creating actual classes, let’s take a moment to think about when they should be used.  Classes should contain groups of related properties, methods, and events.

    For instance, we could create a code class that is used to find information about cars in our inventory.  The class could return a Car object.  This object would most likely have some properties that set or return information about the car, such as Color, Size, Make, or Model.  It might also have methods that refer to actions performed on or by the car, such as StartEngine, EngageBrake, or BeginSale.  Finally, the Car object could also expose methods that notify our script or program when certain events happen to the car.  These might be EngineStarted, ScheduledMaintenance, or SaleCompleted.

    As you can see, all of the functions that would be needed by a sales lot could easily be packaged into a single code class.  This allows the code to be easily ported from one application to another, and also allows for a single point of update, which makes managing future upgrades more feasible.  Aside from that, VBScript is an object-oriented programming language, so it only makes good sense to take advantage of that coding style.

    A code class in VBScript is quite simply a group of functions enclosed in a Class structure.  The scripting engine handles the rest for you.  Today we’re going to be creating a class that can create Compressed Folders natively in WSH.  So to begin, we’ll create a class named CompressedFolder.

    Class CompressedFolder

     

    End Class

    Voilà!  We now have a code class.  When the scripting engine parses this bit of code, it will create an object reference for our new class.  We can connect to that in your script using the following syntax.

    Set objZipFolder = New CompressedFolder

    Of course, at this point our class doesn’t actually do anything.  We need to add the relevant code for it to be useful.  It’s important to note that, with the exception of variable declarations, all code in a class must be procedural.  In other words, all code inside of your class must be contained in either a Function, Sub, or Property block.

    More Code Examples Articles
    More By Nilpo


     

    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