VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry-VBForums
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

Hybrid View

  1. #1

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

    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,092
    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
    32,866
    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
    32,866

    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
    32,866

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

  23. #23

  24. #24
    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.

  25. #25

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

    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.

  26. #26
    New Member
    Join Date
    Jul 2007
    Posts
    2

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

    It seems to me that you are using different application names in GetSetting and SaveSetting functions-

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

    and

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

    I don't know the full logic of your program, but if this is true then you are not reading from the same location in regisrty as you are writing to, unless the App.EXEName is "TestSummitSvr"



    Quote Originally Posted by draven2kg
    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.

  27. #27
    Junior Member
    Join Date
    Apr 2007
    Posts
    30

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

    You can use this information for checkboxes too ...just use you'r mind...

    This is how i did it ...

    There is a TextBox called Text1 on my form and it is invisible ... and there is a checkbox and a timer (value = 10)

    And this is the code :

    Code:
    Private Sub Check1_Click()
    If Check1.Value = 0 Then Text1.Text = "UnChecked"
    If Check1.Value = 1 Then Text1.Text = "Checked"
    End Sub
    
    Private Sub Form_Load()
    Text1.Text = GetSetting(App.EXEName, "textboxes", "text1", "")
    
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
    SaveSetting App.EXEName, "textboxes", "text1", Text1.Text
    End Sub
    
    Private Sub Timer1_Timer()
    If Text1.Text = "Checked" Then Check1.Value = 1
    Timer1.Enabled = False
    End Sub


    P.S

    Anyone knowes how can i save the content of a listbox in registry ??

  28. #28

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

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

    Sure. Loop through the entries saving them to a string separated by something that's not likely to be in any of them like "||" and then write that string to the registry. When you want to restore them use Split on what GetSetting returns.

  29. #29
    Member
    Join Date
    Jan 2009
    Posts
    56

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

    Hi!

    This is really useful, thanks!

    My question is, how can i make if statement on loading that checks if this value is already saved?

    I want to do something like this


    If SOMETHING THAT CHECKS IF VALUE IS SAVED <> "" Then
    Command1.enabled = false
    Else
    End If

    Basicly i want to check that if value is already saved then disable save button...



    Regards

  30. #30
    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

  31. #31

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

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

    I don't know. You are probably better off if you post a question in one of the other forums.

  32. #32
    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?

  33. #33
    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

  34. #34
    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

  35. #35

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

    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]

  36. #36
    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.

  37. #37

  38. #38
    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

  39. #39

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

    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

  40. #40
    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

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.