Jerry Grey Member Posted July 28, 2004 Member Share Posted July 28, 2004 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 More sharing options...
0 azcodemonkey Posted August 6, 2004 Share Posted August 6, 2004 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 More sharing options...
0 Jerry Grey Member Posted August 7, 2004 Author Member Share Posted August 7, 2004 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 More sharing options...
0 Jerry Grey Member Posted August 7, 2004 Author Member Share Posted August 7, 2004 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 More sharing options...
0 azcodemonkey Posted August 8, 2004 Share Posted August 8, 2004 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. Link to comment Share on other sites More sharing options...
0 Jerry Grey Member Posted August 8, 2004 Author Member Share Posted August 8, 2004 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 More sharing options...
0 Jerry Grey Member Posted August 8, 2004 Author Member Share Posted August 8, 2004 Heres the error: Operator '<>' is not defined for types 'Microsoft.Win32.RegistryKey' and 'Microsoft.Win32.RegistryKey'. for the code: If r <> Nothing Then Thanks Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 8, 2004 Share Posted August 8, 2004 [edit] Something's wrong with your install, methinks. Link to comment Share on other sites More sharing options...
0 Jerry Grey Member Posted August 8, 2004 Author Member Share Posted August 8, 2004 [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 More sharing options...
0 Jerry Grey Member Posted August 9, 2004 Author Member Share Posted August 9, 2004 anyone, can help please? Link to comment Share on other sites More sharing options...
0 azcodemonkey Posted August 9, 2004 Share Posted August 9, 2004 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 More sharing options...
0 Jerry Grey Member Posted August 10, 2004 Author Member Share Posted August 10, 2004 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 More sharing options...
0 Winston Posted August 10, 2004 Share Posted August 10, 2004 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 More sharing options...
0 azcodemonkey Posted August 10, 2004 Share Posted August 10, 2004 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 More sharing options...
0 Winston Posted August 10, 2004 Share Posted August 10, 2004 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 More sharing options...
0 azcodemonkey Posted August 11, 2004 Share Posted August 11, 2004 oops! hehe... Link to comment Share on other sites More sharing options...
0 Jerry Grey Member Posted August 11, 2004 Author Member Share Posted August 11, 2004 Yep, now its work..... Thanks for your help.. :D Link to comment Share on other sites More sharing options...
Question
Jerry Grey Member
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
41 answers to this question
Recommended Posts