if myobj Is Nothing then
'object not yet created
'or referece has been set to Nothing
else
'object exists
end if
is one way that you might achieve what you want.
Take care though
if you routinely define your objects such as
Code:
dim myObj as new MyClass
i.e. using the new keyword. The code above will always show that the object exists as any reference to the object, will automatically create it if it doesn't exist
Take Care
Matt
If at first you don't succeed, skydiving is not for you.
if myobj is nothing only checks for any associations for the object and is not related to checking the very exsistance of the object.Please suggest something else.Thanx for your reply
I think you're getting confused between allocating objects on the stack vs. heap-dwelling objects. VB6 does not have that distinction -- they are all COM objects and are allocated by the COM memory allocator.
If you have two object variables pointing at the same instance of an object:
Code:
Dim A As MyObject
Dim B As MyObject
Set A = New MyObject
Set B = A
Then there is no difference as far as you're concerned -- they both aren't Nothing. The fact that they're pointing at the same memory is something that you as the programmer need to be aware of (Gee, how did A's value change when I updated B?).
COM takes care of destroying the last object reference when the variables go out of scope (It uses reference counting -- when it gets to 0, it destroys the object). This is why using local variables (as opposed to global or module-level variables) is so important -- it makes sure the object gets destroyed when you no longer need it. Good programming practice also indicates that you should set your object variables to Nothing when no longer needed:
Code:
Set A = Nothing
Set B = Nothing
Chip H.
If you want to get the best response to a question, please check out FAQ222-2244 first
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.