Results 1 to 5 of 5

Thread: Reading & writing to the registry

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2002
    Location
    Florida, USA
    Posts
    93

    Reading & writing to the registry

    How can I write and read from the registry?

  2. #2
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    u can use GetSetting and SaveSetting

    sample

    VB Code:
    1. '// Make a new project. Add a module. To the form add three text boxes and two command buttons.
    2.  
    3. '// Code:
    4. '// Add this code To the module:
    5.  
    6. Option Explicit
    7.  
    8. Public Const ThisApp = "My Company"
    9. Public Const ThisKey = "My Prog Name"
    10.  
    11. Global Name As String
    12. Global Phone As String
    13. Global PostCode As String
    14.  
    15. '// Add this code To the first Command button:(Load)
    16.  
    17. Private Sub Command1_Click()
    18.     Dim Name, Phone, PostCode As String
    19.  
    20.     Name = GetSetting(ThisApp, ThisKey, "Name", "")
    21.     Phone = GetSetting(ThisApp, ThisKey, "Phone", "")
    22.     PostCode = GetSetting(ThisApp, ThisKey, "PostCode", "")
    23.  
    24.     Text1.Text = (Name)
    25.     Text2.Text = (Phone)
    26.     Text3.Text = (PostCode)
    27. End Sub
    28.  
    29. '// Add this code To the Second Command button:(Save)
    30.  
    31. Private Sub Command2_Click()
    32.     Dim Name, Phone, PostCode As String
    33.  
    34.     SaveSetting ThisApp, ThisKey, "Name", Text1.Text
    35.     SaveSetting ThisApp, ThisKey, "Phone", Text2.Text
    36.     SaveSetting ThisApp, ThisKey, "PostCode", Text3.Text
    37. End Sub
    -= a peet post =-

  3. #3
    Bouncy Member darre1's Avatar
    Join Date
    May 2001
    Location
    Peterborough, UK
    Posts
    3,828
    note that if you want to be able to specify exactly where you want to put values in the registry and have more functionality with the registry you have to use the API registry funtions.
    Confucious say, "Man standing naked in biscuit barrel not necessarily ****ing crackers."

    Don't forget to format your code in your posts

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    darre1 is right, this tutorial might help if u want to accomplish this : http://161.58.186.98/registry/registry2/
    -= a peet post =-

  5. #5
    Fanatic Member SeaHag's Avatar
    Join Date
    Jul 2001
    Location
    Lake Huron
    Posts
    901
    This works too.

    Lots of people suggest useing API. I always suggest this
    because its not alot of code.

    Can anyone tell me whats better, this or API?


    VB Code:
    1. Private Sub Command1_Click()
    2. Dim WshShell As Object
    3. Set WshShell = CreateObject("wscript.Shell")
    4. WshShell.RegWrite "HKLM\software\dumbtest\Value", "Update", "REG_SZ"
    5. Debug.Print WshShell.RegRead("HKLM\software\dumbtest\Value")
    6.  
    7. WshShell.RegDelete "HKLM\software\dumbtest\Value" 'deletes value
    8. WshShell.RegDelete "HKLM\software\dumbtest\Value\" 'deletes entire key
    9. Set WshShell = Nothing
    10. End Sub


    That is all
    Seahag

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