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:
<html><body>
<!-- Empty_Class.html
- Copyright (c) 2015, 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
</script></pre>
</body></html>