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

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