jcworlditsme
New Member
I want to check if there is an instance of an object in a variable. How do i do that?<BR>I try using "Is" but that only checks for variable type, not for an actually instance.<BR><BR>This is the Pseudo-Code for what I want:<BR><BR>If oPerson Is Not Person Then<BR> oPerson = New Person(2)<BR>End IfWhat I need to do is drink more coffee and type:<BR><BR>If Not oPerson Is New Person Then<BR> oPerson = New Person(2)<BR>End If<BR>Return oPerson<BR><BR>There, that works.
what I tried in the previous post didn't work so I worked around the whole thing. I don't know if it's Good thinking or terrible programming, but you'll let me know. This is what I did:<BR><BR>Public ReadOnly Property Person() As Person<BR> Get<BR> Try<BR> If Not m_Person.IsFilled Then<BR> m_Person = New Person(Me.PersonID)<BR> End If<BR> Catch ex As Exception<BR> m_Person = New Person(Me.PersonID)<BR> End Try<BR><BR> Return m_Person<BR> End Get<BR>End Property<BR><BR>In this property I want to return a person but I want to create and fill them on the fly, since that will save me some power.<BR>I check if the is_Filled property is true, if this throws an exception, that means that the object doesn't exists and I create it in the catch. After the object has been created, it won't need to be recreated for later use. Is there an easier way of doing this?? I cant think of any.Try using the IsNothing function to determine whether the object has been assigned to the object varible.<BR><BR><BR>http://msdn.microsoft.com/library/en-us/vblr7/html/vafctIsNothing.asp<end-of-file/>
