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

Silly object syntax question, but can't figure it out 3

Status
Not open for further replies.

oppcos

Programmer
Dec 1, 2004
209
0
0
US
I'm trying to determine if a variant has been set to Nothing or not and I'm not having any success finding examples for some reason. Here is one of my experiments that didn't work:
Code:
Class someClass
	Public z
End Class

Dim Fu
Set Fu = new someClass
Fu.z = "Test"
MsgBox(Fu.z)
Set Fu = Nothing
' ...
If Fu <> Nothing Then MsgBox("Fu is not nothing...")
'Comparing Fu to Nothing above throws the runtime error.

What is the proper way to check if a variant is an object or if it is unset? Sorry if this is a real newbie question..
 
And this ?
If Not (Fu Is Nothing) Then MsgBox("Fu is not nothing...")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
ug! Thank you! I had tried If Fu Is Not Nothing because I'm an idiot. If Fu Is Nothing and If Not Fu Is Nothing both work perfectly. After my first attempt I was too stuck looking for some magical built-in procedure like IsEmpty to keep looking at the simple answer..

Thanks! (And great link chmohan.) I think you all responded at pretty much the same time, and I spent waaay too much time on this silly problem, so stars for all.
 
Try
Code:
if Fu is Nothing then MsgBox "Fu is nothing"
'
' Was the value assigned using set
if IsObject (Fu) then MsgBox "Fu is an object"
'
' Was the value assigned without set
Fu = null
if IsNull(Fu) then MsgBox "Fu is null"
 
Yep, thanks again xwb. It is good advice to continue on and do those checks. Unfortunately I was trying IsObject and IsNull (and IsEmpty, etc) and never got the first bit, Is Nothing going correctly.. and wasted a couple hours feeling really stupid. Turns out, I was just really stupid. ;) FAQ? Or am I the only one who has struggled with that..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top