GWKB2033 : Creating Custom Objects in VBScriptProduct: Window-Eyes
Author: Aaron Smith
Date Added: 08/16/2013
Last Modified: 08/16/2013
Using an object to store and retrieve information can provide you with a comprehensive way to move data between various routines and different parts of your script. You can store data in an object's properties, and you can retrieve data using an object's methods, just like those objects available through the Window-Eyes COM interface.
VBscript provides a powerful method of creating custom objects by allowing you to instantiate a "copy" of a class, whose statements identify the properties and methods of the resulting object.
Let's jump right in with a simple example:
Class Dog Public Name Public Color Public Breed End Class
This class sets up a structure to define a dog, and it includes three read/write properties: Name, Color, and Breed. To instantiate an instance of this class as an object, so that you can read and modify the parameters, use the New statement.
Set myDog = New Dog
The variable myDog is now an instantiated object based on the Dog class. You can now modify the object's properties, like this:
myDog.Name = "Rover" myDog.Color = "Brown" myDog.Breed = "Beagle"
You can then retrieve the property data the same way you would for any other object:
Dim myDogsName : myDogsName = myDog.Name Dim myDogsColor : myDogsColor = myDog.Color Dim myDogsBreed : myDogsBreed = myDog.Breed
- private variables
- methods (Get/Set/Let)
- events: Class_Inititate & Class_Terminate