Chapter 8. Classes in VBScript (Writing Your Own COM Objects)

Even though the feature has existed for some time, most people don't know that you can define classes in VBScript. This gives VBScript programmers a powerful tool, especially in more extensive script-based projects. Granted, classes defined in VBScript do not have the more properly object-oriented capability of Java, C++, VB.NET, or even Visual Basic 6, but they do let the VBScript programmer take advantage of a few of the object oriented benefits available when programming in those other languages.

If you've skipped previous chapters and are not familiar with how to use COM objects from VBScript, then you might benefit from reading the first sections of Chapter 7 before tackling this chapter. This chapter assumes that you are familiar with the basics of instantiating objects and calling their properties and methods.

Objects, Classes, and Components

Before you get too far into how to write your own classes in VBScript, and where you can make use of them, this section covers some terminology. Few technical terms in recent years have been misused, obscured, morphed, and confused more than class, object, and component. Often the terms are used interchangeably, even though they do have distinct meanings. This lack of clarity drives object-oriented purists crazy, but it also makes these waters difficult for beginners to navigate. Let's clear the fog a little bit.

In the strict sense, an object is an in-memory representation of ...

Get VBScript Programmer's Reference, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.