• 0

[VB.NET] How do you get the program to read...


Question

Q: How do you get the program to read a Registry Key?

I know how to Create a Registry Key with:

My.Computer.Registry.CurrentUser.CreateSubKey("MyTestKey")

Thanks for any help! :D

Link to comment
Share on other sites

Recommended Posts

  • 0

Are you sure that r is not null?

          Dim r As Microsoft.Win32.RegistryKey
           r = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\LBluePlanet\CurrentVersion")
           If r <> Nothing Then
                result = CType(r.GetValue("Welcome",1), Integer)
           Else
                result = 1
           End If

Link to comment
Share on other sites

  • 0

CODE  
       Public Function GetTheValue() As Integer
           Dim result As Integer

           Dim r As Microsoft.Win32.RegistryKey
           r = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\LBluePlanet\CurrentVersion")
           result = CType(r.GetValue("Welcome", 1), new Integer)

           r.Close()

           Return result
       End Function

The whole thing ^^

Link to comment
Share on other sites

  • 0
CODE ?
 ? ? ? Public Function GetTheValue() As Integer
 ? ? ? ? ? Dim result As Integer

 ? ? ? ? ? Dim r As Microsoft.Win32.RegistryKey
 ? ? ? ? ? r = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\LBluePlanet\CurrentVersion")
 ? ? ? ? ? result = CType(r.GetValue("Welcome", 1), new Integer)

 ? ? ? ? ? r.Close()

 ? ? ? ? ? Return result
 ? ? ? End Function

The wh:cry:hing ^^

anyone?? :cry:

Link to comment
Share on other sites

  • 0
Did you test r for not being equal to nothing? That's the only place I could see where something wouldn't be an instance of an object.

I did, but it come up with a different error too... :cry:

Link to comment
Share on other sites

  • 0

Heres the error:

Operator '<>' is not defined for types 'Microsoft.Win32.RegistryKey' and 'Microsoft.Win32.RegistryKey'.

for the code:

If r &lt;&gt; Nothing Then

Thanks

Link to comment
Share on other sites

  • 0
[edit]

Something's wrong with your install, methinks.

I think something is wrong with Visual Basic 2005 Express Beta, too. :yes:

Link to comment
Share on other sites

  • 0

Try something like this( this worked for me in VB.NET 2005 ):

       Dim k As RegistryKey
        k = Registry.CurrentUser.OpenSubKey("Software\Intel\Indeo\5.0")

        If (k Is Nothing) Then
            System.Console.WriteLine("k is nothing")
        Else
            System.Console.WriteLine(CType( _
                k.GetValue("Transparency", 1), Integer))
        End If

It's not your install of Express. RegistryKey doesn't overload the inequality operator.

Link to comment
Share on other sites

  • 0

Nope, it doesn't work... :(

The code runs without no errors but its does work :blink: :wacko:

Heres the whole code:

Namespace My
    Partial Friend Class MyApplication
        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As System.Windows.Forms.StartupEventArgs) Handles Me.Startup
            If GetTheValue() = True Then
                MainMenu.Show()
            Else
                SetTheValue()
                Welcome.Show()

            End If
        End Sub

        Public Sub SetTheValue()
            Dim r As Microsoft.Win32.RegistryKey
            r = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\LBluePlanet\CurrentVersion")
            r.SetValue("Welcome", 1)
            r.Close()
        End Sub

        Public Function GetTheValue() As Integer
            Dim k As Microsoft.Win32.RegistryKey
            k = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\LBluePlanet\CurrentVersion")
            If (k Is Nothing) Then
                System.Console.WriteLine("k is nothing")
            Else
                System.Console.WriteLine(CType( _
                k.GetValue("Welcome", 1), Integer))
            End If
        End Function
    End Class
End Namespace

But when I run it for a second time Welcome form still comes up.... :unsure: :(

I might give up on this bit...

Thanks for any help you can give me...

Link to comment
Share on other sites

  • 0

Am i reading wrong? :s, you've got a function GetTheValue() of return type Integer, and you have a If then statement that does a boolean comparison? :s

Link to comment
Share on other sites

  • 0

Holy cow... yeah, that might help if you actually return the value, too.

      Public Function GetTheValue() As Integer
           Dim k As Microsoft.Win32.RegistryKey
           k = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\LBluePlanet\CurrentVersion")
           Return CType( k.GetValue("Welcome", 1), Integer))
       End Function

Do this:

         Try
               If( GetTheValue() == 1 ) Then
                   MainMenu.Show()
               End If
           Catch
               SetTheValue()
               Welcome.Show()
            End Try

Link to comment
Share on other sites

  • 0
Do this:

? ? ? ? ?Try
 ? ? ? ? ? ? ? If( GetTheValue() == 1 ) Then
 ? ? ? ? ? ? ? ? ? MainMenu.Show()
 ? ? ? ? ? ? ? End If
 ? ? ? ? ? Catch
 ? ? ? ? ? ? ? SetTheValue()
 ? ? ? ? ? ? ? Welcome.Show()
 ? ? ? ? ? ?End Try

heh i dont think they use the double equals for comparison in VB, it's the good old assignment operator as well

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.