Classes In Classic ASP
Last updated: 2008-01-30 00:00:00
One great feature of Classic ASP with VBScript programming is the Class. Here I describe a little about the basics of using classes.
There are a number of benefits to using classes in VBScript
I'll write another article that covers all of the benefits, but for now I'll just list a few.
Benefits of using ASP/VbScript classes
- Classes make it easy to keep things organized and simple
- Classes are the only way to do variable scoping
- You need classes to be able to do Object Oriented Programming (OOP)
- Classes provide another way of thinking about the functionality your code provides
You must declare the class, and code it's members before you can us it. Here is a very basic class:
class Book
private m_name
private m_author
public sub Create(name, author)
m_name = name
m_author = author
end sub
public function GetName
GetName = m_name
end function
public function GetAuthor
GetAuthor = m_author
end function
public function GetNameAndAuthor
GetNameAndAuthor = m_name & " by " & m_author
end function
end class
And here is how it would be used:
dim someBook
set someBook = new Book
someBook.Create("Two Years Before the
Mast", "Richard Henry Dana")
response.write someBook.GetNameAndAuthor
This should output the following:
Two Years Before the Mast by Richard Henry Dana
There is a lot there, and I'll try to clarify everything for you when I expand on this article.
