This content is not currently approved and is visible here for review only.

Classic ASP - Introduction to VBScript classes

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!

You might also like...

Comments

Leave a comment

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.” - Rich Cook