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.
Printable View
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.
http://www.vbforums.com/attachment.p...id=47243&stc=1
I created this thread for you.
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.
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.Quote:
Originally Posted by suai
To store the currently selected item in the registry...
...and retrieve it on loading.VB Code:
SaveSetting App.EXEName, "Last Settings", "Root Key", cboHKEY.ListIndexAs 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.VB Code:
cboHKEY.ListIndex = Val(GetSetting(App.EXEName, "Last Settings", "Root Key", 1))
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.
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?
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
Did you look at the link in Martin's signature entitled "Using SaveSetting And GetSetting To Store And Retrieve Data From The Registry"?Quote:
Originally Posted by suai