Forum Moderators: open

Message Too Old, No Replies

Asp

ASP object question

         

ken4runner

8:53 pm on Oct 4, 2005 (gmt 0)

10+ Year Member



I have been looking for a while for an asp function that will tell me if an ASP object, an object like a recordset, has been instantiated/created or not.

basically, I am looking for a "does this object exist" type of function.

It is looking like there is no way to do this....

isempty, isnull, isobject... none of these functions will work for me - they won't tell me if the object has been created or not.

I know this is not an ASP forum, but I thought I would ask anyway. Maybe someone will know

Easy_Coder

9:08 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does this help you?

set o = server.CreateObject("adodb.recordset")
response.Write typename(o)

Easy_Coder

9:29 pm on Oct 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And vartype(o) will return a vbconstant value in this case 9 which is equal to vbObject.

ken4runner

12:50 pm on Oct 5, 2005 (gmt 0)

10+ Year Member



Mr Easy_Coder -

thank you for the tip. that was exactly what I was looking for, and it worked perfectly.

Either vartype or typename - both will tell me if an object was created or not.

after that, I can close the recordset, and then set it to nothing, and then at the very end, close the database connection and set it to nothing.

in case anyone else has this same problem, here is some code, for a generic object called, um, object...

'''''''''''''''''''''''''''''''''''''''''''''''
if typename(object) = "Empty" then
response.write ("<br>typename was " & typename(object) & ".")

elseif typename(object) = "Recordset" then
response.write ("<br>typename was " & typename(object) & ".")
object.Close
set object= nothing
end if
'''''''''''''''''''''''''''''''''''''''''''''''
this checks the object, if it exists (if it has been instantiated) it is closed and then set to nothing.

After doing that for all the objects, then the db connection can be closed, and then set to nothing.

Easy_Coder

2:54 pm on Oct 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



you can also check the state of your connection when you're ready to wrap things up

if conn.State = adStateOpen then
conn.close()
end if