ASP Class Constructors

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post May 27th, 2004, 2:07 am

Hi

Does ASP have any form of class constructors that accept arguments?

something like the PHP solution
Code: [ Select ]
class superCheese{
  function superCheese($var){
   //PHP Code
  }
}

$obj = new superCheese("this is going to the constructor");
  1. class superCheese{
  2.   function superCheese($var){
  3.    //PHP Code
  4.   }
  5. }
  6. $obj = new superCheese("this is going to the constructor");


I have looked at the class_initialize() call but it doesn't like arguments being passed to it.

I have found a work around but it means I have to call the same sub twice and this irritates me

Any ideas ?:idea:
Watch me grow
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post May 27th, 2004, 2:07 am

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post May 27th, 2004, 3:35 am

I'm not that far along in my ASP education yet, but I found this that appears to answer the question:

http://aspnet.4guysfromrolla.com/articles/102302-1.aspx

If not, you might try this google search exactly as displayed:
asp class constructors arguments

THere are quite a few results returned from that search that might asnwer the question.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post May 27th, 2004, 3:50 am

Thanks for that. Didn't quite answer the question but gave me an idea to look on.

Seems that ASP can't automate the construction of a class.

You have to create an instance of the object then call the constructor where as with PHP if th function name is the same as the class it will automatically execute the function

ASP:
classObj = new className
classObj.ConstructMe(args)

PHP
classObj = new className(args)

I know I am being picky but it is an extra line of code!

Anyways if anyone else comes up with a solution or idea lemme know.

Thanks again
Watch me grow
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Joined: May 28, 2003
  • Posts: 23407
  • Loc: Woodbridge VA
  • Status: Offline

Post May 27th, 2004, 4:00 am

I see what you are saying. This will be a good thread to remember when I get to that point. Good luck, and please update us if/when you do find an answer.
"There's no place like 127.0.0.1 except for ::1."
Alexandria Networks. Leader in IT consulting for associations/non-profits, and small to medium sized businesses around the northern Virginia and Washington D.C. metro area.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post May 27th, 2004, 5:17 am

ATNO/TW wrote:
I see what you are saying. This will be a good thread to remember when I get to that point. Good luck, and please update us if/when you do find an answer.


Will keep everyone informed :wink:
Watch me grow
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Joined: Apr 28, 2004
  • Posts: 1099
  • Status: Offline

Post May 28th, 2004, 10:04 am

Code: [ Select ]
class some_class
 [public/private subs,functions and properties here]
end class

set classobj = new some_class
some_value = classobj.some_get_property_of_class(args)
  1. class some_class
  2.  [public/private subs,functions and properties here]
  3. end class
  4. set classobj = new some_class
  5. some_value = classobj.some_get_property_of_class(args)


That's the way you do it, in a nutshell and VERY (^100) simplistically, in VBScript for ASP. .NET might have some shorthand ways, although I doubt it. C# maybe, but I doubt VB.NET doesn't it much different than it always has...

.c
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post May 30th, 2004, 11:22 pm

Carnix wrote:
Code: [ Select ]
class some_class
 [public/private subs,functions and properties here]
end class

set classobj = new some_class
some_value = classobj.some_get_property_of_class(args)
  1. class some_class
  2.  [public/private subs,functions and properties here]
  3. end class
  4. set classobj = new some_class
  5. some_value = classobj.some_get_property_of_class(args)


That's the way you do it, in a nutshell and VERY (^100) simplistically, in VBScript for ASP. .NET might have some shorthand ways, although I doubt it. C# maybe, but I doubt VB.NET doesn't it much different than it always has...

.c


Thanks that is the way I am currently using it, was hoping there was a shorter way but alas ...
Watch me grow

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 107 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.