Results 1 to 12 of 12

Thread: Registry in VB Express 2005

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    Question 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!

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    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)
    Frans

  3. #3

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    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.

  6. #6
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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:
    1. ' My count.
    2.     Private iCount As Integer = 0
    3.  
    4.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    5.         ' Do something with my count.
    6.         MessageBox.Show(iCount.ToString())
    7.         ' Increment the count.
    8.         iCount += 1
    9.     End Sub

    Good luck.

  7. #7

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    Re: Registry in VB Express 2005

    Okay!
    Thanks! Saved my day
    Last edited by silverferret; Jul 4th, 2007 at 01:19 AM.

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    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
    ??

  9. #9

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    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!

  10. #10
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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

  11. #11

    Thread Starter
    New Member
    Join Date
    Nov 2006
    Posts
    11

    Re: Registry in VB Express 2005

    What about my last post? the one with 'Test.Test' ...?

  12. #12
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    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:
    1. ' Check for a key in the registry.
    2.         Dim key As Microsoft.Win32.RegistryKey = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion")
    3.         If key IsNot Nothing Then
    4.             MessageBox.Show("Found the key")
    5.         Else
    6.             MessageBox.Show("Didn't find the key")
    7.         End If
    8.  
    9.         ' Check for a value in the key.
    10.         If My.Computer.Registry.GetValue("HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion", "ProductId", Nothing) IsNot Nothing Then
    11.             MessageBox.Show("Found the value")
    12.         Else
    13.             MessageBox.Show("Didn't find the value")
    14.         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
  •  



Click Here to Expand Forum to Full Width