如何检查注册表项对象是否= Nothing? [英] How can I check whether or not a registry key object is = Nothing?

查看:57
本文介绍了如何检查注册表项对象是否= Nothing?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Gang,

有时当我尝试打开注册表时它不存在,因此

对象引用等于什么。但是VB.NET 2003不允许使用

语法如果

如果objReg<>什么都没有

''这样做

结束如果


有人能告诉我另一种方法来检查密钥是否打开失败?我b $ b意识到我可以使用错误处理,但我更喜欢把它作为最后的

度假胜地:)。

干杯,
Christian

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

推荐答案



" Christian Blackburn" <基督教@该死@ SP ** @ Hotmail.com>在消息中写道

news:eU ************* @ tk2msftngp13.phx.gbl ...

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> wrote in message
news:eU*************@tk2msftngp13.phx.gbl...
Hi Gang,有时当我尝试打开注册表时它不存在,因此
对象引用等于什么都没有。但是VB.NET 2003不允许
语法如果
如果objReg<>什么都没有
''这样做
结束如果
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




运营商=和<>是处理对象的运算符。但没有什么

不是一个对象。这只是一个参考。没有什么是参考对象失败

的参考。它是空指针。 VB。


您需要运算符作为对象引用标识:''是''。

如果不是objReg什么都没有那么

''这样做

结束如果


''是''是一个对引用而不是对象进行操作的运算符。它告诉你

两个引用是否相等。两个引用是相同的,以防万一

它们引用相同的对象,或者两者都没有。


David



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


您好,


" Christian Blackburn" <基督教@该死@ SP ** @ Hotmail.com> schrieb:
Hello,

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb:
有时当我尝试打开注册表时它不存在
因此对象引用等于什么都没有。但是如果
如果objReg<>那么VB.NET 2003就不允许语法。什么都没有
''这样做
结束如果
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




\\\

如果不是objReg是什么都没有

...

结束如果

///


-

Herfried K. Wagner

MVP·VB Classic,VB.NET
http://www.mvps.org/dotnet


非常感谢David和Herfried,

我肯定会使用我刚刚学到的数万亿次。:

干杯,

Christian

Herfried K. Wagner [MVP]" <喜******* @ m.activevb.de>在消息中写道

新闻:%2 *************** @ TK2MSFTNGP12.phx.gbl ...
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...
你好,

Christian Blackburn <基督教@该死@ SP ** @ Hotmail.com> schrieb:
Hello,

"Christian Blackburn" <Christian@Damn@Sp**@Hotmail.com> schrieb:
有时当我尝试打开注册表时它不存在
因此对象引用等于什么都没有。但是如果
如果objReg<>那么VB.NET 2003就不允许语法。什么都没有
''这样做
结束如果
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



\\\
如果不是objReg什么都没有那么
.. 。
结束如果
///

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



这篇关于如何检查注册表项对象是否= Nothing?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆