title: "Use the 'new' keyword to create an object instance" error in VB .Net
body: <p>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 <code>HKEY_CURRENT_USER\Software\MyApp\TEST</code></p>
  
  <p>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 </p>
  
  <pre><code>regkey = Registry.LocalMachine.OpenSubKey("HKEY_CURRENT_USER\Software\MyApp\TEST", True) 
  </code></pre>
  
  <p>, still not sure why its 
  value is not picked up by program. </p>
  
  <p>How do I implement New keyword to create an object instance ? 
  I am using "Imports Microsoft.Win32" at the top level in program.</p>
  
  <pre><code> 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
  </code></pre>