IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
ASP Classic
Search ASP Classic Group:

Advanced
-Collapse +Expand ASP Classic Store

Prestwood eMagazine

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

   ► KBWebsite Scri...ASP ClassicOOP   Print This     
  From the January 2016 Issue of Prestwood eMag
 
ASP Classic OOP:
ASP Classic Constructors (Class_Initialize)
 
Posted 16 years ago on 1/18/2009
ASP Classic Code Snippet:
 A flashcard from our ASP Classic Flashcards Library
 A code snippet from our ASP Classic Code Snippets Page

KB101823

General Info: Class Constructor

Constructors are called when you instantiate an object from a class. This is where you can initialize variables and put code you wish executed each time the class is created. When you initially set the member fields and properties of an object, you are initializing the state of the object. The state of an object is the values of all it's member fields and properties at a given time.

Languages Focus: Constructor

What is the syntax? Can you overload constructors? Is a special method name reserved for constructors?

ASP Classic Constructors

When an object instance is created from a class, ASP calls a special parameter-less sub named Class_Initialize. Since you cannot specify parameters for this sub, you also cannot overload it.

When a class is destroyed, ASP calls a special sub called Class_Terminate.

Syntax Example:
Class Cyborg
  Public CyborgName
 
 Public Sub Class_Initialize
   Response.Write "<br>Class created"
   CyborgName = "Cameron"
  End Sub 
End Class

Working Example

The following working example contains both a constructor and destructor, ASP's Class_Initialize and Class_Terminate subs. In this example, we are implicitly destroying the object (letting IIS destroy the object when the variable goes out of scope).

You can explicitly destroy an object by using Set MyRobot = Nothing. In ASP Classic, it is recommended that you explicitly destroy all objects.

<%@LANGUAGE=VBScript%>
<%Option Explicit%>
<html>
<body>
  
<%
Dim MyRobot
Set MyRobot = new Cyborg
Response.Write "<br>My robot's name is " & MyRobot.CyborgName & "."
  
//Object destroyed implicitly here
//and Class_Terminate is called.
%>
  
</body>
</html>
  
<%
Class Cyborg
 Public CyborgName
 
 Public Sub Class_Initialize
  Response.Write "<br>Class created"
  CyborgName = "Cameron"
 End Sub
 
  
 Public Sub Class_Terminate
  Response.Write "<br>Class destroyed"
 End Sub 
End Class

%> 

More Info

Definition:  Class Constructor

Comments

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

You have great knowledge about ASP Classic Constructors and you have experience in the field too. I write my essay for me cheap and explain a few new things to the new students which I gain by experience.

Posted 53 months ago

Comment 2 of 4

Activate mcafee software in your devices

Visit McAfee Activate official site mcafee.com/initiate in any program.
Enter your 25 digits McAfee Activation Product Key.
Sign in to your McAfee account with certifications.
Snap Submit and Choose "Nation and language".
When Logged in, Download your Setup in download envelope.
Run application to introduce, You‘re good to go to go!
mcafee.com/activate

Posted 53 months ago

Comment 3 of 4

Activate webroot software in your devices

Go to webroot safe site webroot com safe from your program.
Sign in Webroot account with your Credentials.
Enter your Webroot Key code have 20 digits.
Snap on Next catch to enroll your Webroot item.
Acknowledge the Agree and Install catch to continue.
At long last your Webroot safe is actuated effectively.
www.webroot.com/safe

Posted 53 months ago

Latest Comment
Comment 4 of 4

I am an editor of an Internet resource. Our service is the best essay helper online, it helps millions of people to save their time. Our goal is to make learning easier and faster than ever. I really like my job and the company in which I work.

Posted 51 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 = P1205A1
Enter key:
Code Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile


Linked Certification Question(s)

The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.

Advanced

1 Advanced Level Question

Question #1: Multiple Choice

In ASP Classic object oriented programming, when an object instance is created from a class, ASP calls a special parameter-less sub named what?

Answer:
1. 

Class_New

2. 

New

3. 

Class_Initialize

4. 

Initialize

5. 

Class_Create


 KB Article #101823 Counter
37110
Since 1/18/2009
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]