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!

How to tell if an object has been created 3

Status
Not open for further replies.

mookie

Programmer
May 3, 2000
15
US
On some of my error handlers I am attempting to output to a log file the current values of different of the variables. The problem I have is determining if I have created the object yet. For example

on error goto main_err

dim bob as client

... <a>

set bob = new client

... <b>

main_err:
debug.print bob.number

So, if I have an error in section <a> I will get another error in the error handler because bob does not exist yet. Is there a VB function that returns a true/false value how whether or not the object exists? Something like this

if exists(bob) then
debug.print bob.number
end if

Thanks
 
Thank you, that was what I was looking for.
 
No problem. I didn't have a clue for ages. I used to catch the specifi error number before I somehow stumbled across this inn a code sample. I don't think its a highly visible test condition - or maybe I just don't read the books/manuals fully!!!!

James :) James Culshaw
jculshaw@active-data-solutions.co.uk
 
Maybe you can use another approach
You can put two errhandler, one for section <a>, the other for section <b>.

on error goto a_err

dim bob as client

... <a>

set bob = new client

on error goto main_err
... <b>


a_err:
MsgBox Err.Number & &quot;-&quot; & Err.Description
Exit Sub
'put an exit or resume next here to avoid VB from process through to next line (main_err)


main_err:
debug.print bob.number

:)



 
psst My two cents :-V

Another thing to keep in mind is how you instantiate or declare varBOB
If you do something like this

Dim varBOB As New BOB

Then when you issue something like this

If varBOB Is Nothing
'This code will Never execute
End if

VB will go and create varBOB so it will never be nothing

But if you instantiate or declare varBOB in any other way besides that then VB will not create varBOB when you issue that statement
Eg

Dim varBOB As BOB


If varBOB Is Nothing
...'This will execute if varBOB is nothing
End if

- or -

Dim varBOB As Object

If varBOB Is Nothing
....
End If

BTW: To test if it is something (not nothing) you can do something like this

If Not varBOB Is Nothing
End If

Have fun ;-)
caf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top