Results 1 to 12 of 12

Thread: [RESOLVED] Registry handling... simple question...

  1. #1

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Resolved [RESOLVED] Registry handling... simple question...

    Ok i have a simple question about registry... I know how to write and retrieve but i have this question:
    When i search for registries examples in google i always find this kind of examples:
    Code:
    SaveSetting("Registry Example", "Form Location", "Left", 200)
    But here in vbforums i saw that to make your app compatible with vista u need to do something like HKEY_CURRENT_USER maybe? i can't find it now
    But i don't know if this would be how to do it:
    Code:
    SaveSetting(HKEY_CURRENT_USER, "Form Location", "Left", 200)
    ?

    My other question is... do i need to compile a vista version and an xp and previous version? or just using vista mods would work on previous??
    Thx!
    REMEMBER if i've been useful RATE me plz

  2. #2

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: Registry handling... simple question...

    ermmm no one? i know its weekend but i don't think this very difficult and other threads are getting resolved :P
    well ill wait... thx!
    REMEMBER if i've been useful RATE me plz

  3. #3
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Registry handling... simple question...

    You can find something here

    I believe you don't have to compile two versions. You can check which OS version is being used with code and make two (or more) separate actions.

  4. #4

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: Registry handling... simple question...

    Kk but for writing them to the HKEY_CURRENT_USER is like i said??
    REMEMBER if i've been useful RATE me plz

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Registry handling... simple question...

    Quote Originally Posted by VB<3er
    Kk but for writing them to the HKEY_CURRENT_USER is like i said??
    What?!

  6. #6

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: Registry handling... simple question...

    :P
    If i want to write to the HKEY_CURRENT_USER...would i do it like this:
    SaveSetting(HKEY_CURRENT_USER, "Example", "example", example.value)
    ??
    REMEMBER if i've been useful RATE me plz

  7. #7
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: Registry handling... simple question...

    VB's registry functions save to HKEY_CURRENT_USER\Software\VB and VBA Program Settings

    Thus SaveSetting("Registry Example", "Form Location", "Left", 200) saves to HKEY_CURRENT_USER\Software\VB and VBA Program Settings\Registry Example

  8. #8

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: Registry handling... simple question...

    Okey so then it is ok for both vista and xp isn't it?
    Ive seen programs writing it like this :
    Code:
    Public Sub SaveString(hKey As Long, strPath As String, strValue As String, strdata As String)
        'EXAMPLE:
        '
        'Call savestring(HKEY_CURRENT_USER, "Sof
        '     tware\VBW\Registry", "String", text1.tex
        '     t)
        '
        Dim keyhand As Long
        RegCreateKey hKey, strPath, keyhand
        RegSetValueEx keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata)
        RegCloseKey keyhand
    End Sub
    Are there many differences between vb builtin and api?
    Thx!
    Last edited by VB<3er; Aug 3rd, 2008 at 11:47 AM.
    REMEMBER if i've been useful RATE me plz

  9. #9

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: Registry handling... simple question...

    Anyone?
    REMEMBER if i've been useful RATE me plz

  10. #10
    PowerPoster Ellis Dee's Avatar
    Join Date
    Mar 2007
    Location
    New England
    Posts
    3,530

    Re: Registry handling... simple question...

    Attached the registry class I wrote/assembled, which will let you read and write to anywhere in the registry.

    Sample usage:
    vb Code:
    1. Dim reg As clsRegistry
    2.  
    3. Set reg = New clsRegistry
    4. reg.WriteNumber "Software\CompanyName\ProgramName\Form Location", "Left", 200
    5. Set reg = Nothing
    The optional last parameter (after the 200) is omitted, which means the call defaults to HKEY_CURRENT_USER.

    Typically I'll make reg public and "Set = New" on startup, then set it back to Nothing when the program terminates. This way I can use it anywhere in my program with minimal hassle.
    Attached Files Attached Files

  11. #11

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: Registry handling... simple question...

    Well thx... i'll see what i do... thx!!
    REMEMBER if i've been useful RATE me plz

  12. #12

    Thread Starter
    Addicted Member VB<3er's Avatar
    Join Date
    Jun 2008
    Location
    VBForums
    Posts
    133

    Re: [RESOLVED] Registry handling... simple question...

    Just my last question... i found this around modified it a bit and it works pefect... but don't really know what it exactly does... there are some things i dun get can some one break it out?? would be so appreaciated!

    Code:
    Public Function GetString(hKey As Long, strPath As String, strVal As String)
    Dim hKeyh As Long
    Dim DataType As Long
    Dim lResult As Long
    Dim strBuf As String
    Dim lDataBufSize As Long
    Dim lValueType As Long
    Dim intZeroPos As Integer
    Call RegOpenKey(hKey, strPath, hKeyh)
    lResult = RegQueryValueEx(hKeyh, strVal, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lValueType = REG_SZ Then
       'Part i don't get... strBuf = String(lDataBufSize, " ")
        lResult = RegQueryValueEx(hKeyh, strVal, 0&, 0&, ByVal strBuf, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            intZeroPos = InStr(strBuf, Chr$(0))
            If intZeroPos > 0 Then
                GetString = Left$(strBuf, intZeroPos - 1)
            Else
                GetString = strBuf
            End If
        End If
    End If
    End Function
    Thx!
    Last edited by VB<3er; Aug 4th, 2008 at 06:57 AM.
    REMEMBER if i've been useful RATE me plz

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