This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
ASP VBScript classes - Outline
Background
You may wonder why write an article on classes in VBScript when there are hundreds of articles already on the web about classes? Well, it's because when I first tried to learn about classes I found it hard to visualise and to "get my head around" the concept of using classes let alone finding basic articles showing how to use them within ASP VBScript.
What I hope to acheive with this article is to provide the reader with a basic understanding of classes in a manner that a complete novice programmer, like my self, would find useful and easy to follow. I also hope to provide a first insight into a more object-orientated programming (OOP) approach in VBScript.
Introduction
So what is a class? A class is basically the coding framework we need to enable an object to be created at runtime. A class it's self does not represent any thing, but the object it lets us create can represent any element or entity that we choose, from a real world object like a car, to a virtual object like an XmlCreator for creating XML data files. A class also allows us to encapsulate any code directly relating to the object we wish to create, and abstract this code out of the "presentation layer" (the page HTML).
In our example we are going to create a class which when instantiated will create an object that will represent a car. The code inside the class is split into two main areas; Properties and Methods. A property is a thing that is owned and in a class we treat one exactly as we would a variable. A method is a way of carrying out an action, possibly on values held in the properties, and you will be familiar with these as Functions or Sub Procedures.
In our car example some properties we may have are:
- Number of wheels
- Colour of paint
- Is engine running?
- Is clutch engaged?
- Current selected gear
Some of the methods we may have are:
- Start engine
- Stop engine
- Depress Clutch
- Release Clutch
- Select gear
So now we have a basic outline of what a class is let's create one!