ASP Class Constructors

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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:
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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
  • ATNO/TW
  • Super Moderator
  • Super Moderator
  • User avatar
  • Posts: 23456
  • Loc: Woodbridge VA

Post 3+ Months Ago

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.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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:
  • Carnix
  • Guru
  • Guru
  • User avatar
  • Posts: 1098

Post 3+ Months Ago

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
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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 ...

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 67 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.