-
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.
-
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:
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
:)
-
I didn't know that. Thanks.
-
Got the gist of both now and thanks very much for your time.
bye
-
how would you do that with a list?
-
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.
-
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
-
I don't have any experience with embedded VB but I did a Google search for getsetting embedded and I came up with this article.
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
Quote:
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>
-
text1.text isn't a file, it's the value of a textbox.
-
can you store the data in registry only in (HKEY_CURRENT_USER|YourAppName)???? how?
-
Search this forum for registry and you'll find a lot of examples like this one.
-
very, very useful information.
-
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!
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
Conquest. Please see this thread.
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
How to save for checkboxes?
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
Very similarly
VB Code:
SaveSetting App.EXEName, "checkboxes or anything you want", "MyCheckbox", text1.Text
' Here I have the default for the checkbox set to be unchecked. You may
' want to change that to vbChecked or even vbGrayed
Check1.Value = GetSetting (App.EXEName, "checkboxes or anything you want", "MyCheckbox", vbUnchecked)
-
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
-
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:
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:
chkA.Value = GetSetting(App.EXEName, "checkboxes\frmdvan", "chkA", "")
I think that probably what you want is
VB Code:
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.
-
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.
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
Did you look in the Registry to see what is there?
-
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:
Option Explicit
Private Sub Form_Load()
chkA.Value = GetSetting("TestSSvr", "checkboxes\frmdvan", "chkA", vbUnchecked)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveSetting "TestSSvr", "checkboxes\frmdvan", "chkA", chkA.Value
End Sub
-
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
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
Sorry but sitting here I can't tell what the problem is.
-
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.
-
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.
-
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
-
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.
-
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?
-
1 Attachment(s)
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) :D
-
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
-
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]
-
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.
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
Show me one of the GetSetting or SaveSetting commands that you use.
-
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
-
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
-
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
-
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.
-
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
-
Re: VB - Using SaveSetting and GetSetting to store and retrieve data from the Registry
No, but you can use any one of several encryption/decryption methods to protect the data.