|
-
Sep 28th, 2006, 09:26 AM
#1
Thread Starter
New Member
Please show me how to store data in the Registry
can u guys give more example for how to store data in text or registry file? I want to learn how to store item inside the combo box and oso it's value. each item hv 5 values i wan to store.
Last edited by MartinLiss; Sep 28th, 2006 at 09:40 AM.
-
Sep 28th, 2006, 09:41 AM
#2
Re: Please show me how to store data in the Registry

I created this thread for you.
-
Sep 28th, 2006, 01:57 PM
#3
Fanatic Member
Re: Please show me how to store data in the Registry
The simplist method for using the registry is to use the standard VB functions:
VB Code:
SaveSetting AppName, Section, Key, Setting
CurrentValue/DefaultValue = GetSetting(AppName, Section, Key, [Default])
DeleteSetting AppName, Section, Key
These functions, however, will only ever save data under the "HKEY_CURRENT_USER\Software\VB and VBA Program Settings" key in the registry. To save anywhere else in the registry, you have to use API calls.
To save the values in the combobox, you would have to setup a loop to go though every entry in the combo box, and save its setting. Upon loading the program, you go though every value in the registry and load it into the combo box.
Your two methods for figuring out how many values are in the registry is either to use a standized naming system, and look for the default value entered to popup and exit, or to use a special entry that contains the number of items/list of the item names.
-
Sep 28th, 2006, 03:26 PM
#4
Re: Please show me how to store data in the Registry
 Originally Posted by suai
how to store data in text ..... file?
Although you can store settings in a text file, it's far easier to put the data in a UDT and store it in a binary file.
To store the currently selected item in the registry...
VB Code:
SaveSetting App.EXEName, "Last Settings", "Root Key", cboHKEY.ListIndex
...and retrieve it on loading.
VB Code:
cboHKEY.ListIndex = Val(GetSetting(App.EXEName, "Last Settings", "Root Key", 1))
As Gaming_World said, you can store the settings elsewhere in the registry in a variety of formats - say as a UDT stored in a REG_BINARY or REG_NONE value, as strings in a REG_MULTI_SZ value, or as individual values of types REG_SZ, REG_DWORD, REG_DWORD_BIG_ENDIAN. The only problems are that you may need to convert data types and you'd need administrative rights to create keys in certain sections of the registry, depending on the OS.
A typical reason for using the less common key types would be for storing a font structure, or an encrypted username and password (in a UDT) and stored as a REG_NONE value.
Last edited by schoolbusdriver; Sep 29th, 2006 at 04:09 AM.
-
Sep 28th, 2006, 10:25 PM
#5
Thread Starter
New Member
Re: Please show me how to store data in the Registry
First of all, thx for MartinLiss for creating this thread for me, and also those who trying to help me. For your all information, it is hard for me to imagine and understand, because i am still new in VB6, so can u guys upload some example?
-
Sep 28th, 2006, 10:47 PM
#6
Lively Member
Re: Please show me how to store data in the Registry
Also you can access to registry via WMI
for example,
VB Code:
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\System Admin Scripting Guide"
strValueName = "Multi String Value Name"
arrStringValues = Array("first string", "second string", _
"third string", "fourth string")
oReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
strValueName,arrStringValues
Also look it in MSDN http://www.microsoft.com/technet/scr...y/default.mspx
-
Sep 29th, 2006, 05:53 AM
#7
Re: Please show me how to store data in the Registry
 Originally Posted by suai
First of all, thx for MartinLiss for creating this thread for me, and also those who trying to help me. For your all information, it is hard for me to imagine and understand, because i am still new in VB6, so can u guys upload some example?
Did you look at the link in Martin's signature entitled "Using SaveSetting And GetSetting To Store And Retrieve Data From The Registry"?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|