I am getting this error "use the 'new' keyword to create an object instance. (Object reference not set to an instance of an object.) "
I checked similar questions on this forum but could not find a satisfactory answer.
what I am trying to achieve is import string value of 1 into registry subkey HKEY_CURRENT_USER\Software\MyApp\TEST
What I noted during Debugging is that "regkey" appears to be set to Null at all the lines where it is used. I am setting
regkey = Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\MyApp\TEST", True)
, still not sure why its value is not picked up by program.
How do I implement New keyword to create an object instance ? I am using "Imports Microsoft.Win32" at the top level in program.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim regkey As RegistryKey
regkey = Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\MyApp\TEST", True)
regkey.SetValue("TEST", "1", RegistryValueKind.String)
regkey.close()
End Sub