By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,890 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,890 IT Pros & Developers. It's quick & easy.

How can I check whether or not a registry key object is = Nothing?

P: n/a
Hi Gang,
Sometimes when I try to open a registry it doesn't exist and therefore the
object reference is equal to nothing. However VB.NET 2003 doesn't allow the
syntax if
If objReg <> Nothing then
'do this
End if

Can somebody tell me another way to check if the key failed to open? I
realize I can just use error handling, but I prefer to make that the last
resort :).
Cheers,
Christian
Nov 20 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> wrote in message
news:eU*************@tk2msftngp13.phx.gbl...
Hi Gang,
Sometimes when I try to open a registry it doesn't exist and therefore the
object reference is equal to nothing. However VB.NET 2003 doesn't allow the syntax if
If objReg <> Nothing then
'do this
End if


The operators = and <> are operators that work on objects. But Nothing
isn't an object. It's just a reference. Nothing is a reference that fails
to refer to an object. It is the "null pointer" of VB.

You need the operator for object reference identity: 'is'.

If not objReg is Nothing then
'do this
End if

'is' is an operator that operates on references, not objects. It tells you
whether two references are equal. Two references are equal just in case
they refer to the same object, or both are Nothing.

David
Nov 20 '05 #2

P: n/a
Hello,

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb:
Sometimes when I try to open a registry it doesn't exist
and therefore the object reference is equal to nothing. However
VB.NET 2003 doesn't allow the syntax if
If objReg <> Nothing then
'do this
End if


\\\
If Not objReg Is Nothing Then
...
End If
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #3

P: n/a
Thank you very much David and Herfried,
I'm sure I'll use what I just learned trillion times over :).
Cheers,
Christian
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl...
Hello,

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb:
Sometimes when I try to open a registry it doesn't exist
and therefore the object reference is equal to nothing. However
VB.NET 2003 doesn't allow the syntax if
If objReg <> Nothing then
'do this
End if


\\\
If Not objReg Is Nothing Then
...
End If
///

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #4

P: n/a
Hello,

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb:
Thank you very much David and Herfried,
I'm sure I'll use what I just learned trillion times over :).


In addition to my previous post:

MSDN says that 'OpenSubKey' returns 'Nothing' if the key doesn't exist.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #5

P: n/a
Hi Herfried,
That is exactly what I said :).
In addition to my previous post:

MSDN says that 'OpenSubKey' returns 'Nothing' if the key doesn't exist.

Sometimes when I try to open a registry [key and] it doesn't exist and therefore theobject reference is equal to nothing.


Thanks so much for all the help Herfried you rate, I even added you to spell
check :).
Cheers,
Christian Blackburn
Nov 20 '05 #6

P: n/a
Hi Herfried

|| Herfried, I even added you to spell check :).

What better compliment?! ;-)

Regards,
Fergus
MVP [Windows Keyboard, PC Power Switch]


Nov 20 '05 #7

P: n/a
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
Herfried, I even added you to spell check :).


What better compliment?! ;-)


Sorry, I don't really understand that...

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #8

P: n/a
Hi Herfried,
It's just that Outlook Express doesn't recognize your name as a word. It's
no big deal it's just, because it's a foreign name. What I'm trying to say
is that I've had to write you thank you so many times that it was worth my
time to add you to spell check. What I'm trying to say with a little bit of
comedy is that you help me a lot and I appreciate it :).
Cheers,
Christian Blackburn
"Herfried K. Wagner [MVP]" <hi*******@m.activevb.de> wrote in message
news:e0*************@TK2MSFTNGP11.phx.gbl...
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
Herfried, I even added you to spell check :).


What better compliment?! ;-)


Sorry, I don't really understand that...

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #9

P: n/a
Hi Herfried, Christian,

Lol, and I was just giving it a bit of emphasis. ;-)

Regards,
Fergus
Nov 20 '05 #10

P: n/a
Hello,

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb:
It's just that Outlook Express doesn't recognize your name as
a word.


I understand it now...

:-)

--
Herfried K. Wagner
MVP VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.