"Class" Statement - Defining Your Own Class

This section provides a tutorial example on how to create a class and instantiate a new object. The TypeName() function returns the class name of the specified object.

Basic things that you need to learn before writing any classes:

1. "Class" Statement - Declares the name of a class and defines properties and methods that comprise the class. Here is the "Class" statement structure:

Class class_name
   ' statements to define properties
   ' statements to define methods
End Class

2. "New" Operator - Instantiates an object from the specified class. Here is the "New" operator syntax:

   Set variable_name = New class_name

3. "Set" Statement - Assigns an object to a variable. Here is the "Set" statement syntax:

   Set variable_name = object_expression

Now I am ready to show you that class is supported in the VBScript host environment provided by IE browser for client-side scripting. Here is my VBScript example that creates an empty class:

<!-- Empty_Class.html
 - Copyright (c) 1998 HerongYang.com. All Rights Reserved.
<pre><script language="vbscript">
   ' Initiating an object from a class
   Dim oEmpty
   Set oEmpty = New EmptyClass

   ' Checking the object
   document.writeln("VarType(oEmpty)=vbObject: " _ 
      & (VarType(oEmpty)=vbObject))
   document.writeln("TypeName(oEmpty): " & TypeName(oEmpty))

' Defining an empty class
Class EmptyClass
End Class

Run this VBScript example in IE, you will get:

VarType(oEmpty)=vbObject: True
TypeName(oEmpty): EmptyClass

Note that "TypeNmae()" function returns the class name of the specified object.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

 Conditional Statements - "If ... Then" and "Select Case"

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

Creating Your Own Classes

 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

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)


 Full Version in PDF/EPUB