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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Server.CreateObject reverse? 1

Status
Not open for further replies.

ReneV

Programmer
Jun 8, 2000
9
NL
Hi. I'm wondering how to determine the type of a object-variable at runtime. I would like to get the class name, if possible.

for instance:

dim oObj
set oObj = server.createObject ("ADODB.Recordset")

dim sName
sName = GetObjectType (oObj)

I'd like sName to read "ADODB.Recordset" after that call.
Obviously I've invented 'GetObjectType' here, so I'm wondering how to implement that function ;-)

Thanks for any info you might share with me.
 
Good question...
There is a function in VBScript called VarType which behaves similarly to Visual Basic, returing the CLSID of the passed parameter. This behaves as you requested:

dim sName
sName = VarType(oObj)

look up the VBScript documentation for more information.
 
Unfortunately, this is simply not true, or at least not in IIS4...

It returns '9' for me, which only tells me that it's an object by looking at the VarType help.
 
Hi

I'm not quite sure what you're doing but let me give this a shot.
The TypeName function returns the true name of the object.

eg

Dim x As object

Set x = CreateObject("ADODB.RecordSet")

Msgbox TypeName(x)

What I don't understand is why you want to do this?
You need the class name to issue a createobject even if it is in a variable

Set x = CreateObject(SomeVariable)

Whay don't you just query the variable instead of querying the object.
You should create & destroy objects in a controlled environment.

Have fun
caf
 
caf,

> What I don't understand is why you want to do this?

I agree, accept that I can also imagine building some 'type-less' functions or something where you would want this information. I hope it never happens to me! (-:

That said, not being a VB person I was unaware of that method so I find the information provided by you very helpful. Thanks

-pete

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top