Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server.CreateObject vs "New" Object

Status
Not open for further replies.

BG12424

Programmer
Jun 4, 2002
717
US
I have a situation with existing code in classic ASP where a previous developer instantiated multiple instances of an object to be used in the web page. See code below

Code:
Set objRO = Server.CreateObject("SampleObj.ClassNameHere")
Set objRO1 = Server.CreateObject("SampleObj.ClassNameHere")
Set objAuth = Server.CreateObject("SampleObj.ClassNameHere")

Could this be accomplished in a better way by doing this instead? See below

Code:
Set objRO = Server.CreateObject("SampleObj.ClassNameHere")
Set rs1 = New objRO
Set rs2 = New objRO
Set rsAuth = New objRO

Please advise... Thanks


regards,
Brian
 
That makes no sense in any programming language i am familiar with. However since it is Visual Basic Script it just might work [lol] They do all sorts of crazy stuff in VB. [bugeyed]

-pete
 
Thanks Pete, aka "Paul"

What makes sense then? Should the 2nd part be better to do, or does that not make sense either? How would this be handled?


regards,
Brian
 
Oh, sorry for the confusion i was speaking only to the second example you posted. The first example, using Server.CreateObject() for each object of course makes sense because that's how you do it. :)

>> Thanks Pete, aka "Paul"

huh? Why do you want me to be Paul and who is Paul?

-pete
 
Pete, the aka was a joke from awhile ago when you emailed me directly. Sorry.

I was just wondering if there was a better way to instantiate the same object 3 times. If this is the only way to do it then that's fine.


regards,
Brian
 
>> if there was a better way

Not when your talking about 3 seperate instances of the same COM Object. And in fact in any environment, i.e. C++ it is similar.

-pete
 
Well New Keyword works well when u have added refrence of that object in ur application.

otherwise u have to say createobject("ProgID")
 
Your mixing vb and vb script.
Server.createobject is ASP, thus vbscript (unless you are talking about ASP.Net

classic ASP you can't use NEW as vbs is not typed thus all objects are held in varient. I think you'll see that if you use NEW your ASP will crash. So its simple use Server.createObject.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top