IIS ASP - How can I test to see whether a particular object variable is defined?

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > August 2004 > How can I test to see whether a particular object variable is defined?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author How can I test to see whether a particular object variable is defined?
Christian Blackburn

2004-08-10, 5:55 pm

Hi Gang,
I want to test and find out whether or not a particular variable object has
been defined. I need to know whether or not a recordset has already been
defined in the current script. However, my script crashes even though I've
disabled error handling, which doesn't make a whole lot of sense to me, but
anyways . Here's my code:
---------------------------------------------------
on Error Resume Next

If objRS.Fields.GetCount > 1 Then
RestartRecordSet()
Else
OpenConnection()
End If

On Error Goto 0
-----------------------------------------------------
Is there some command like If isdef(objRS) then... or something to that
effect? Also is .GetCount the correct command? I think it is, but MSDN
help has a special way of giving too much information.

Thanks in advance,
Christian Blackburn





Ray at

2004-08-10, 5:55 pm

Well, there is the IsObject function, but that's not completely reliable.
If you create an object and then destroy it, IsObject will still return a
true if you test if the variable is an object. So, you could use an On
Error Resume Next in conjunction with trying to access a property
(preferably the default property) of your object.

Example:

<%
Dim oADO
Response.Write IsObject(oADO) & " - should be false<br>"
Set oADO = CreateObject("ADODB.Connection")
Response.Write IsObject(oADO) & " - should be true<br>"
Set oADO = Nothing
Response.Write IsObject(oADO) & " - you'd think it'd be false, but it's
true.<br>"

On Error Resume Next
sTemp = oADO.ConnectionString
Response.Write "Is really an object that still exists in memory? " &
(Err.Number = 0)
On Error Goto 0
%>

Ray at work







"Christian Blackburn" <Christian_Blackburn@Damn.Spam@Hotmail.com> wrote in
message news:u6wxmsvfEHA.3632@TK2MSFTNGP11.phx.gbl...
> Hi Gang,
> I want to test and find out whether or not a particular variable object
> has
> been defined. I need to know whether or not a recordset has already been
> defined in the current script. However, my script crashes even though
> I've
> disabled error handling, which doesn't make a whole lot of sense to me,
> but
> anyways . Here's my code:
> ---------------------------------------------------
> on Error Resume Next
>
> If objRS.Fields.GetCount > 1 Then
> RestartRecordSet()
> Else
> OpenConnection()
> End If
>
> On Error Goto 0
> -----------------------------------------------------
> Is there some command like If isdef(objRS) then... or something to that
> effect? Also is .GetCount the correct command? I think it is, but MSDN
> help has a special way of giving too much information.
>
> Thanks in advance,
> Christian Blackburn
>
>
>
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com