Page 1 of 2 12 LastLast
Results 1 to 40 of 51

Thread: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Here is how to use the Registry


    ' Save text1's value
    SaveSetting App.EXEName, "textboxes", "text1", text1.Text

    ' Get text1's value
    text1.text = GetSetting (App.EXEName, "textboxes", "text1", "")

    SaveSetting stores the data in the Registry (in HKEY_CURRENT_USER|Software|VB and VBA Program Settings|YourAppName). The four parts of the function are the name under which it is stored (App.EXEName in this case), "textboxes" in this example is like the section name in an ini file, "text1" is like the key in a line of data in the ini file, and text1.text is the value.

    GetSetting returns the value. The 4th parameter ("" in this case) is optional and it is the default if no registry entry is found.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    You can also go deeper than one level if you feel you need to for organizational purposes. Just use a backslash ("\") to separate the key names...
    VB Code:
    1. Call SaveSetting(App.EXEName, "Textboxes\frmMain", "Text1", frmMain.Text1.Text)

    will create a key under "HKEY_CURRENT_USER\Software\VB and VBA Program Settings\YourAppName\Textboxes\frmMain

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3

  4. #4
    Member Romano's Avatar
    Join Date
    Jan 2003
    Location
    Uk
    Posts
    40
    Got the gist of both now and thanks very much for your time.


    bye
    Romano

    Link

  5. #5
    Junior Member
    Join Date
    Jun 2003
    Location
    Dallas, TX
    Posts
    21
    how would you do that with a list?

  6. #6

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427
    It depends on the size of the list. If it's a reasonably small list you could combine the data in a string separated by some unusual character and store it in one registry entry. Otherwise you should use a database or textfile to store the data.

  7. #7
    Junior Member
    Join Date
    Sep 2003
    Location
    Ft. Worth, TX
    Posts
    16
    Have you ever tried saving to a registry in a Windows CE device.... i'm actually usine Embedded CE 3.0 which is very similar to vb6, but there are some differences.....i tried your code but it didn't recognize savesettings must be something similar with a ce device

  8. #8

  9. #9
    Junior Member
    Join Date
    Sep 2003
    Location
    Ft. Worth, TX
    Posts
    16

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Originally posted by MartinLiss
    Here is how to use the Registry


    ' Save text1's value
    SaveSetting App.EXEName, "textboxes", "text1", text1.Text

    ' Get text1's value
    text1.text = GetSetting App.EXEName, "textboxes", "text1", "")

    SaveSetting stores the data in the Registry (in HKEY_CURRENT_USER|Software|VB and VBA Program Settings|YourAppName). The four parts of the function are the name under which it is stored (App.EXEName in this case), "textboxes" in this example is like the section name in an ini file, "text1" is like the key in a line of data in the ini file, and text1.text is the value.

    GetSetting returns the value. The 4th parameter ("" in this case) is optional and it is the default if no registry entry is found.

    <B>Where is you text1.text file located????</B>

  10. #10

  11. #11
    New Member
    Join Date
    Apr 2004
    Posts
    11
    can you store the data in registry only in (HKEY_CURRENT_USER|YourAppName)???? how?

  12. #12

  13. #13
    Hyperactive Member kayos's Avatar
    Join Date
    Apr 2004
    Location
    Largo, Florida
    Posts
    306
    very, very useful information.


    If this post helps, please RATE MY POST!

    Using Visual Studio 2005 SE

  14. #14
    New Member
    Join Date
    May 2005
    Location
    Europe,Croatia,Bjelovar
    Posts
    4

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Hy, I'm new here but I understand in VB very good,
    can You tell me how to save text from MSFlexGrid!
    It's not bad to learn something new

  15. #15

  16. #16
    Member
    Join Date
    Aug 2005
    Posts
    40

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    How to save for checkboxes?

  17. #17

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Very similarly


    VB Code:
    1. SaveSetting App.EXEName, "checkboxes or anything you want", "MyCheckbox", text1.Text
    2.  
    3. ' Here I have the default for the checkbox set to be unchecked. You may
    4. ' want to change that to vbChecked or even vbGrayed
    5. Check1.Value = GetSetting (App.EXEName, "checkboxes or anything you want", "MyCheckbox", vbUnchecked)

  18. #18
    Member
    Join Date
    Aug 2005
    Posts
    40

    Unhappy Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    I am trying to get the value of a checkbox that i have compiled in an exe.



    This Function is in an activex component. It calls the form and checks the value that should be by default turned on in my exe. However, i seem to be having some trouble getting the value. Reading this post i thought the code below will give me the value of either 1 or 0 but that doesnt seem to be the case.

    Public Function GetValue()

    Dim AValue

    AValue = GetSetting("TestSSvr", "checkboxes\frmdvan", "chkA", "")

    GetValue = AValue

    End Function

    ' I dont seem to be getting anything here
    'Using this code AValue = GetSetting("TestSSvr", "checkboxes\frmdvan", "chkA", vbUnchecked) I get a 0 all the time????



    '==========Here is the code that saves the value in my exe to the registry 'of the checkbox.This code works in loading the value from the registry and saving to it. But i dont seem to be able to get the value from my active x component when i call it(^Above)



    Private Sub Form_Load()

    chkA.Value = GetSetting(App.EXEName, "checkboxes\frmdvan", "chkA", "")


    End Sub




    Private Sub cbOK_Click()


    SaveSetting App.EXEName, "checkboxes\frmdvan", "chkA", chkA.Value


    End Sub
    Last edited by draven2kg; Sep 2nd, 2005 at 04:45 PM. Reason: typo

  19. #19

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    I'm not sure I understand, but let me point out that
    VB Code:
    1. AValue = GetSetting("TestSSvr", "checkboxes\frmdvan", "chkA", "vbUnchecked")

    will look in the Registry for HKEY_CURRENT_USER|Software|VB and VBA Program Settings|TestSSvr|checkboxes\frmdvan|frmdvan and if it doesn't find that entry it will return the string vbUnchecked because you have that value in quotes. If you aren't aware vbUnchecked is a built-in VB constant with a value of 0, so if you want to use it with your checkbox you should remove the quotes.

    Similarly in your second example where you have
    VB Code:
    1. chkA.Value = GetSetting(App.EXEName, "checkboxes\frmdvan", "chkA", "")
    I think that probably what you want is
    VB Code:
    1. chkA.Value = GetSetting(App.EXEName, "checkboxes\frmdvan", "chkA", vbUnchecked)

    If that doesn't fix your problem you should use regedit and look for HKEY_CURRENT_USER|Software|VB and VBA Program Settings and see if it has a sub-folder named TestSSvr (and/or whatever your exe name is) and see what values are stored in that/those subfolders.

  20. #20
    Member
    Join Date
    Aug 2005
    Posts
    40

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    It was a typo. But what i want is..


    Public Function GetValue()

    Dim AValue

    AValue = GetSetting("TestSSvr", "checkboxes\frmdvan", "chkA", "")

    GetValue = AValue

    End Function


    To give me the current value of the checkbox. ...vbUnchecked just gives me 0 all the time.
    Last edited by draven2kg; Sep 2nd, 2005 at 05:13 PM.

  21. #21

  22. #22

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Put this in a form and you'll see that it works.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.  
    5.     chkA.Value = GetSetting("TestSSvr", "checkboxes\frmdvan", "chkA", vbUnchecked)
    6.    
    7. End Sub
    8.  
    9.  
    10. Private Sub Form_Unload(Cancel As Integer)
    11.  
    12.     SaveSetting "TestSSvr", "checkboxes\frmdvan", "chkA", chkA.Value
    13.  
    14. End Sub

  23. #23
    Member
    Join Date
    Aug 2005
    Posts
    40

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    I have this code in my ASP page..it makes a call to my active x component which in turn checks the registry to find the value of the key.


    Dim CallChkAudit
    Dim AuditOnOff

    Set CallChkAudit = Server.CreateObject("SummitSvr.WebSvr")

    AuditOnOff = CallChkAudit.GetAuditValue




    This is the code in my active x component...and it reads the registyr to find the value of the checkbox. Which should on default be turned on...

    This is where i keep getting a 0.....and if i use

    AValue = GetSetting("TestSummitSvr", "checkboxes\frmTestAdvanced", "chkAudit", vbUnchecked) i get blank


    Public Function GetAuditValue()

    Dim AValue

    AValue = GetSetting("TestSummitSvr", "checkboxes\frmTestAdvanced", "chkAudit", vbUnchecked)


    GetAuditValue = AValue


    End Function




    this 2 sections of code are in my exe form which saves the value of the checkbox and the other which loads the current value for the check box


    Private Sub cbOK_Click()

    'Use to get value from registry
    'Dim value As String
    'value = GetSetting("TestSummitSvr", "checkboxes\frmTestAdvanced", "chkAudit", "Default")



    'Saves checkbox value of form to registry
    SaveSetting App.EXEName, "checkboxes\frmTestAdvanced", "chkAudit", chkAudit.Value


    End Sub



    Private Sub Form_Load()

    chkAudit.Value = GetSetting(App.EXEName, "checkboxes\frmTestAdvanced", "chkAudit", vbUnchecked)



    End Sub
    Last edited by draven2kg; Sep 2nd, 2005 at 05:38 PM.

  24. #24

  25. #25
    Member
    Join Date
    Aug 2005
    Posts
    40

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    The following code is in a class module in a dll :

    I have a dll that makes a call to get a checkboxes value from my registry.
    However i keep getting a 0 which i think is the default value or a vbUnchecked value. What am i doing wrong?




    visual basic code:--------------------------------------------------------------------------------Public Function GetAuditValue() As Variant

    Dim AValue As Variant


    AValue = GetSetting("TestSummitSvr", "checkboxes\frmTestAdvanced", "chkAudit", vbUnchecked)



    Dim fso2, txtfile2

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txtfile = fso.OpenTextFile("C:\test\testfile2.txt", 8, True)

    txtfile.WriteLine AValue
    txtfile.Close



    GetAuditValue = AValue


    End Function--------------------------------------------------------------------------------



    This prints a 0 to my text file even though the key in my registry is a 1









    The codes below are in an exe on a form that has a check box that i have to save and get the settings from registry.




    visual basic code:--------------------------------------------------------------------------------Private Sub cbOK_Click()

    SaveSetting App.EXEName, "checkboxes\frmTestAdvanced", "chkAudit", chkAudit.Value

    End Sub--------------------------------------------------------------------------------




    I use this code to get the checkboxes registry value when form loads from registry....
    visual basic code:--------------------------------------------------------------------------------Private Sub Form_Load()

    chkAudit.Value = GetSetting(App.EXEName, "checkboxes\frmTestAdvanced", "chkAudit", vbUnchecked)

    End Sub

    --------------------------------------------------------------------------------

    Here is a slight change.

  26. #26

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    "This prints a 0 to my text file even though the key in my registry is a 1"

    That doesn't seem possible. Put a breakpoint on the Set fso line and see what is in AValue.

  27. #27
    Member
    Join Date
    Aug 2005
    Posts
    40

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    When i take this code and put it in a form with a command botton it works good. Could it be something that is happening b/w the dlls ?




    Public Function GetAuditValue() As Variant

    Dim AValue As Variant


    AValue = GetSetting("TestSummitSvr", "checkboxes\frmTestAdvanced", "chkAudit", vbUnchecked)



    Dim fso2, txtfile2

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txtfile = fso.OpenTextFile("C:\test\testfile2.txt", 8, True)

    txtfile.WriteLine AValue
    txtfile.Close



    GetAuditValue = AValue


    End Function

  28. #28

  29. #29
    Member
    Join Date
    Aug 2005
    Posts
    40

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Git any suggestions how else i can save a checkboxes value?

  30. #30
    Addicted Member
    Join Date
    Apr 2005
    Posts
    248

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Quote Originally Posted by draven2kg
    Git any suggestions how else i can save a checkboxes value?

    It's a bit.. old fashioned, but it's how all my programs work. Hope it can be some help, if not, well, I tried (I'm a bit of a noob at VB though)
    Attached Files Attached Files

  31. #31
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    so how could u dele them? can u show me like a path to which i can find them

  32. #32

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Quote Originally Posted by Ebiru
    so how could u dele them? can u show me like a path to which i can find them
    Post #1 says where they are. You can either manully delete them or use DeleteSetting

    DeleteSetting AppName, [Section], [Key]

  33. #33
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registr

    Quote Originally Posted by MartinLiss
    Post #1 says where they are. You can either manully delete them or use DeleteSetting

    DeleteSetting AppName, [Section], [Key]
    i see cant find it....whats the actual path....HKEY_CURRENT_USER|Software|VB and VBA Program Settings|YourAppName that doesnt help me.

  34. #34

  35. #35
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Code:
    SaveSetting App.EXEName, name, "badguy", badguy(x).left
    there is one
    name = name of the player

  36. #36

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    So assuming the name of your project is Project1 then you will find an entry in the Registry at

    HKEY_CURRENT_USER|Software|VB and VBA Program Settings|Project1

  37. #37
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registr

    Quote Originally Posted by MartinLiss
    So assuming the name of your project is Project1 then you will find an entry in the Registry at

    HKEY_CURRENT_USER|Software|VB and VBA Program Settings|Project1
    just saying that still isnt clear to me. can u explain alittle more in detail

  38. #38

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    Have you ever looked inside the Registry? If not then do Start|Run|Regedit and you will see something that looks similar to Windows Explorer. One of the first "folders" will be HKEY_CURRENT_USER. One of it's "sub-folders" will be "Software", etc.

  39. #39
    Addicted Member
    Join Date
    Mar 2006
    Posts
    226

    Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry

    also is there a way to secure them? so like people dont just go in n edit them

  40. #40

Page 1 of 2 12 LastLast

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