|
-
Jul 2nd, 2007, 06:14 AM
#1
Thread Starter
New Member
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!
-
Jul 2nd, 2007, 08:57 AM
#2
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)
-
Jul 2nd, 2007, 09:49 AM
#3
Re: Registry in VB Express 2005

I've moved your thread.
-
Jul 2nd, 2007, 01:17 PM
#4
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).
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Jul 3rd, 2007, 01:09 AM
#5
Thread Starter
New Member
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]
Last edited by penagate; Jul 3rd, 2007 at 05:22 AM.
-
Jul 3rd, 2007, 08:11 AM
#6
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.
-
Jul 4th, 2007, 01:09 AM
#7
Thread Starter
New Member
Re: Registry in VB Express 2005
Okay!
Thanks! Saved my day
Last edited by silverferret; Jul 4th, 2007 at 01:19 AM.
-
Jul 4th, 2007, 01:23 AM
#8
Thread Starter
New Member
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
??
-
Jul 4th, 2007, 02:00 AM
#9
Thread Starter
New Member
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!
-
Jul 4th, 2007, 07:55 AM
#10
Re: Registry in VB Express 2005
 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
-
Jul 5th, 2007, 01:15 AM
#11
Thread Starter
New Member
Re: Registry in VB Express 2005
What about my last post? the one with 'Test.Test' ...?
-
Jul 5th, 2007, 08:55 AM
#12
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|