Registry in VB Express 2005
I want to store the information in the form into the registry.
Heres my code:
Code:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim Value As String
Value = ComboBox1.Text
My.Computer.Registry.CurrentUser.CreateSubKey("MRU")
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\", _
"MRU", "" & Value)
End Sub
If I press Button3, it creates a value "MRU" in HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\
BUT.. If I put something else in the ComboBox, it overwrites the registry value when I press Button3 again.
How is it possible to make it add MRU1, MRU2, ect ?
Now I have MRU0 to MRU10 in the registry.
If I press the Button3 now, it creates MRU key, but if I edit the value in the combobox, it overwrites.
I want it to create MRU11, MRU12, ect...
Thanks in advanced!
Re: Registry in VB Express 2005
Post this question in the .NET forum please.
You will get better results.
This forum is for classic VB (up to version 6)
Re: Registry in VB Express 2005
Re: Registry in VB Express 2005
If you run My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\", "MRU", "" & Value), it will set the value of MRU. To set the value of MRU1, you have to run My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\", "MRU1", "" & Value). You can use a variable for the number - My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\", "MRU" & iCounter, "" & Value).
Re: Registry in VB Express 2005
okay.
I got it..
But.. One more question though..
When I press "Button3", it overwrites the MRU0... I want it to add the next one..
Let's say i have MRU0, MRU1, MRU2.
I have this in the code:
Code:
My.Computer.Registry.SetValue("HKEY_CURRENT_USER\Software\Microsoft\Terminal Server Client\Default", _
"MRU" & iCounter, "" & Value)
Now..
When I press "Button3", I want it to add MRU3 to the registry automaticly.
And when I press "Button3" again after that, I want it to add MRU4 to the registry automaticly.
You guys with me now??
[Please don't bump your threads. - Mod]
Re: Registry in VB Express 2005
You can consider setting your iCount as a class level variable and increment it every time you click the button.
vb.net Code:
' My count.
Private iCount As Integer = 0
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Do something with my count.
MessageBox.Show(iCount.ToString())
' Increment the count.
iCount += 1
End Sub
Good luck.
Re: Registry in VB Express 2005
Okay!
Thanks! Saved my day ;)
Re: Registry in VB Express 2005
Ok..
What is the code for when I close (exit) the form?
Is it:
Code:
Private Sub Form1_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
End Sub
??
Re: Registry in VB Express 2005
One more thing about the registry...
If .. lets say 'test' value exists in the registry...
Like..
Name:
'Test0'
Type:
REG_SZ
Value:
Test.Test
And when I press 'Button3', it creates Test1 with the value 'Test.Test'..
(If 'Test.Test' is in the combobox that is!)
I want it to NOT save it in to the registry if the value 'Test.Test' exists...
How is this possible?
Thanks!
Re: Registry in VB Express 2005
Quote:
Originally Posted by silverferret
Ok..
What is the code for when I close (exit) the form?
Is it:
Code:
Private Sub Form1_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
End Sub
??
To insert the code for a certain control's events you can:
1) Select the control in the desinger and click the Events button (lightening bolt) in the Properties window.
2) In code view in the left combo box select the desired control and then in the right combo box select the desired event
Re: Registry in VB Express 2005
What about my last post? the one with 'Test.Test' ...?
Re: Registry in VB Express 2005
You can do something like this to check for a key (example 1) or a value in the key (example 2):
vb.net Code:
' Check for a key in the registry.
Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion")
If key IsNot Nothing Then
MessageBox.Show("Found the key")
Else
MessageBox.Show("Didn't find the key")
End If
' Check for a value in the key.
If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProductId", Nothing) IsNot Nothing Then
MessageBox.Show("Found the value")
Else
MessageBox.Show("Didn't find the value")
End If
Hope that helps.