I.T. Discussion Community!
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

May Edition
Subscribe now! It's Free!
Enter your email:

   ► KBWebsite Scri...ASP ClassicTool Basics   Print This     
  From the June 2009 Issue of Prestwood eMag
 
ASP Classic Tool Basics:
Creating a Class in ASP
 
Posted 13 years ago on 2/17/2006 and updated 10/18/2008
Take Away: Create a basic Class in ASP
 Tags: ASP , Classes

KB100304



Sometimes it is useful to create your own Classes and Objects (an instantiation of a class) in ASP, below is the basic code to create one.

Class Person 
	Public Function IntroduceYourself() 
	Response.Write("Hello, my name is " & Name & ", it's nice to meet you!") 
	End Function 
	Public Name 
End Class 

The above code declares a class. This class has one Public member - Name and one Public function - IntroduceYourself.

To use this class:

Set Adam = new Person		//Create Adam object using the Person class.
Adam.Name = "Adam" //Set Name property.
Adam.IntroduceYourself() //Call the IntroduceYourself method.

Set Adam = new Person creates an Object of type Person and assigns it to the variable name Adam. Adam.Name ="Adam" assigns the string "Adam" to the Adam-Person Object's Name attribute. Adam.IntroduceYourself calls the Adam-Person Objects IntroduceYourself function. The output of this little demo should politely say Hello, my name is Adam, it's nice to meet you!

Complete Example

Here is a complete example within a single HTML page. Notice I declared the class at the end of the HTML to show you that where you define your class is not important. Usually developers put classes into their own files.

<html>
<head>
<title>Test Page</title>
</head>
<body>
<h1>Introduce Yourself</h1>
<%
Set Adam = new Person //Create Adam object using the Person class.
Adam.Name = "Adam" //Set Name property.
Adam.IntroduceYourself() //Call the IntroduceYourself method.
%>
</body>
</html>
<%
Class Person
 Public Function IntroduceYourself()
  Response.Write("Hello, my name is " & Name & ", it's nice to meet you!")
 End Function
 
 Public Name
End Class
%>

Linked Message Board Threads

 Creating Classes in ASP in ASP Classic Coding MB Topic (1 replies)

Comments

1 Comments.
Share a thought or comment...
Comment 1 of 1

2014 and I'm just getting into classes! Our site was build with Classic ASP and has grown since; in too deep to change now! My programming skills have evolved and I came to classes as a result of frustration at trying to pick my way through my old code. This super-simple example has got me up and running. Wish I'd found it years and years ago!

Thank you for having written it Adam, your post is still doing great service.

Hugh

---
Hugh
Posted 57 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P1235A1
Enter key:
KB Post Contributed By Adam Lum:

Adam Lum is a part time developer for Prestwood Software and participates in this online community when time allows. His day-to-day work is C# coding but his current intrests (right now) are Ruby on Rails and iOS programming with Objective-C.  He has also coded several projects in Java, C++, ASP Classic, and PHP.  His personal website can be found at adamlum.com.

Visit Profile

 KB Article #100304 Counter
8857
Since 4/2/2008
Follow PrestwoodBoards on: 


©1995-2019 PrestwoodBoards  [Security & Privacy]
Professional IT Services: Coding | Websites | Computer Tech