How do determine if an object is uninitialized?

A

Alexandre

Hi, I would like to do this

If (myObject = uninitialized) the
set myObject = new Objec
End i

I have trying it with the following keywords but it doesnt work: Empty, Null, Nothing

Thanks!
 
G

Gale Green

Hi, I would like to do this:

If (myObject = uninitialized) then
set myObject = new Object
End if

I have trying it with the following keywords but it doesnt work: Empty, Null, Nothing.

This must be one of the commonest questions asked on the VB
newsgroups.

If MyObject Is Nothing

or

If Not (MyObject Is Nothing)

Gale.
 
B

Bob O`Bob

Gale said:
This must be one of the commonest questions asked on the VB
newsgroups.

If MyObject Is Nothing

or

If Not (MyObject Is Nothing)


Philosophically, it makes sense to me.

'Nothing' is the absence of a value. None whatsoever.
This is quite distinct from having any value at all.

Therefore, it can't be "equal to" any value.
Not even another 'Nothing'

If it had a value and could be compared for equality,
then it would not be sufficiently distinct from zero.



Bob
 
G

Gale Green

Philosophically, it makes sense to me.

'Nothing' is the absence of a value. None whatsoever.
This is quite distinct from having any value at all.

Therefore, it can't be "equal to" any value.
Not even another 'Nothing'

If it had a value and could be compared for equality,
then it would not be sufficiently distinct from zero.

I agree entirely.

The problem I still have with VB though, after decades of working with
a language that won't let you do it, is the fact that

If MyObjectOfType1 = MyObjectOfType2 Then

is actually allowed, if the default properties of the two objects are
compatible.

I *never* use default properties, but always type

If MyObjectOfType1.PropertyX = MyObjectOfType2.PropertyY Then

It can be a real pain, downloading code from the Internet and then
ploughing through it inserting all the missing default properties, but
I always do it.

If Text1 = List1 Then
MsgBox "Aaaagh!"
EndIf

Gale.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top