Results 1 to 7 of 7

Thread: Please show me how to store data in the Registry

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    11

    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.

  2. #2

  3. #3
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962

    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:
    1. SaveSetting AppName, Section, Key, Setting
    2. CurrentValue/DefaultValue = GetSetting(AppName, Section, Key, [Default])
    3. 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.
    Involved in: Sentience

  4. #4
    Fanatic Member schoolbusdriver's Avatar
    Join Date
    Jan 2006
    Location
    O'er yonder
    Posts
    1,020

    Re: Please show me how to store data in the Registry

    Quote 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:
    1. SaveSetting App.EXEName, "Last Settings", "Root Key", cboHKEY.ListIndex
    ...and retrieve it on loading.
    VB Code:
    1. 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.

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    11

    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?

  6. #6
    Lively Member okosv's Avatar
    Join Date
    Sep 2006
    Posts
    95

    Re: Please show me how to store data in the Registry

    Also you can access to registry via WMI
    for example,
    VB Code:
    1. Const HKEY_LOCAL_MACHINE = &H80000002
    2.  
    3. strComputer = "."
    4.  
    5. Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
    6.     strComputer & "\root\default:StdRegProv")
    7.  
    8. strKeyPath = "SOFTWARE\System Admin Scripting Guide"
    9. strValueName = "Multi String Value Name"
    10. arrStringValues = Array("first string", "second string", _
    11.     "third string", "fourth string")
    12.  
    13. oReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _
    14.     strValueName,arrStringValues

    Also look it in MSDN http://www.microsoft.com/technet/scr...y/default.mspx

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Please show me how to store data in the Registry

    Quote 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
  •  



Click Here to Expand Forum to Full Width