VBScript Tutorials - Herong's Tutorial Notes
Dr. Herong Yang, Version 5.00

Class, Property, Method and Related Statements

This section describes general rules on creating your own classes in VBScript. A list of class related statements is provided.

Can you create your own class with VBScript? The answer is yes.

VBScript allows you to write a class with the following rules:

  • Use "Class class_name" statement to define a class.
  • Property members can be defined using class-level variables.
  • Property members can also be defined using "Property" procedures
  • Method members can be defined using function procedures and subroutine procedures
  • Class-level variables can be defined as "Private" for inside-class use only.
  • Procedure can be defined as "Private" for inside-class use only.
  • Initialization procedure can be defined for a new object.
  • Clean up procedure can be defined for a terminating object.

Things that you need to learn for creating your own classes:

  • "Class" Statement - Declares the name of a class and defines properties and methods that comprise the class.
  • "Property Let" Statement - Defines a property procedure to allow values, not objects, to be assigned to a property.
  • "Property Set" Statement - Defines a property procedure to allow objects, not values, to be assigned to a property.
  • "Property Get" Statement - Defines a property procedure to return values or objects of a property.
  • "Public" Statement - Declares variables to be used as public properties accessible inside and outside this class.
  • "Private" Statement - Declares variables to be used as private variables accessible only inside this class.
  • "Public" Qualifier - Declares procedures to be used as public methods accessible inside and outside this class.
  • "Private" Qualifier - Declares procedures to be used private procedures accessible only inside this class.
  • "Public Default" Qualifier - Declares a procedure to be the default public method accessible inside and outside this class.
  • "New" Operator - Instantiates an object from the specified class.
  • "Set" Statement - Assigns an object to a variable.
  • "Class_Initialize" Subroutine Procedure - Initializes a new object.
  • "Class_Terminate" Subroutine Procedure - Clears a terminating object.
  • "Nothing" Object - Releases the object reference of stored in the variable when assigned to a variable.

Sections in This Chapter

Class, Property, Method and Related Statements

"Class" Statement - Defining Your Own Class

"New" Operator and "Nothing" Object

"Public/Private" Variables and Dot Operator

"Property Let/Set/Get" Procedures

Object Methods - "Public" Procedures

"New", "Set", "Is", ".", "Nothing" - Object Operations

"StringBuffer" - A Class Example

Dr. Herong Yang, updated in 2008
Class, Property, Method and Related Statements