首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

asp.net(vb.net)读注册表出现:未将对象引用设置到对象的实例解决思路

2012-03-16 
asp.net(vb.net)读注册表出现:未将对象引用设置到对象的实例SubReadreg()DimregAsMicrosoft.Win32.Registr

asp.net(vb.net)读注册表出现:未将对象引用设置到对象的实例
Sub   Readreg()
                Dim   reg   As   Microsoft.Win32.RegistryKey,   subreg   As   Microsoft.Win32.RegistryKey
                reg   =   Microsoft.Win32.Registry.CurrentUser
                subreg   =   reg.OpenSubKey( "Software\test ",   True)
                If   subreg.GetValue( "ok ")   <>   " "   Then
                        Dim   str   As   Object   =   subreg.GetValue( "ok ")
                        lblSimpleCode.Text   =   str.ToString()
                Else
                        lblsimplecode.Text= "no   value "
                End   If
        End   Sub
==================
If   subreg.GetValue( "EofficeNo ")   <>   " "   Then     这句出现未将对象引用设置到对象的实例
这也是在网上找的例子。请高手帮忙。第一次操作注册表

[解决办法]
我才试了,代码没有问题,你直接复制过去看看
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim reg As Microsoft.Win32.RegistryKey, subreg As Microsoft.Win32.RegistryKey
reg = Microsoft.Win32.Registry.CurrentUser
subreg = reg.OpenSubKey( "Software\test ", True)

If (subreg IsNot Nothing) Then
If subreg.GetValue( "ok ") <> " " Then
Dim str As Object = subreg.GetValue( "ok ")
Debug.WriteLine(str.ToString())
Else
Debug.WriteLine( "no value ")
End If
Else
Debug.WriteLine( "no this key ")
End If
End Sub
[解决办法]
重新写了一下,运行通过!
Sub Readreg()
Dim reg As Microsoft.Win32.RegistryKey, subreg As Microsoft.Win32.RegistryKey
reg = Microsoft.Win32.Registry.CurrentUser
subreg = reg.OpenSubKey( "Software\test ", True)
If Not subreg Is Nothing Then
If subreg.GetValue( "ok ") <> " " Then
Dim str As Object = subreg.GetValue( "ok ")
lblSimpleCode.Text = str.ToString()
Else
lblSimpleCode.Text = "no value "
End If
Else
subreg = reg.CreateSubKey( "Software\test ")
subreg.SetValue( "ok ", "hello! ")
Dim str As Object = subreg.GetValue( "ok ")
lblSimpleCode.Text = str.ToString()
End If
End Sub

热点排行