'===========================================================================
' Subject: REGISTRY MODULE                    Date: 05-13-00 (15:32)       
'  Author: Jeremiah Hyde                      Code: VB5                    
'  Origin: fishoffire@yahoo.com             Packet: VBWIN.ABC
'===========================================================================
Attribute VB_Name = "SimpleRegistry"
'PPPPPP
'PP  PP
'PP  PP  rr rrr   oooo    ggg gg  rr rrr   aaaa   mm  mm    eeee   rr rrr   zzzzzz
'PPPPP    rrr rr oo  oo  gg  gg    rrr rr     aa  mmmmmmm  ee  ee   rrr rr  z  zz
'PP       rr  rr oo  oo  gg  gg    rr  rr  aaaaa  mmmmmmm  eeeeee   rr  rr    zz
'PP       rr     oo  oo   ggggg    rr     aa  aa  mm m mm  ee       rr       zz  z
'PP      rrrr     oooo       gg   rrrr     aaaaa  mm   mm   eeee   rrrr     zzzzzz
'                         ggggg                               (  /\__________/\  )
'   ###########                                                \(^ @___..___@ ^)/
'   # ___ ___ #   RRRRR            lll            !!   !!       /\ (\/\/\/\/) /\
'   { (0) (0) }   RR  RR            ll           !!!! !!!!     /  \(/\/\/\/\)/  \
'   |    P    |   RR  RR  uu  uu    ll   zzzzzz  !!!! !!!!   -(    """"""""""    )
'    \ \___/ /    RRRRR   uu  uu    ll   z  zz   !!!! !!!!    \      _____      /
'      \___/      RR RR   uu  uu    ll     zz     !!   !!     (     /(   )\     )
'  Jeremiah "BJ"  RR  RR  uu  uu    ll    zz  z               _)   (_V) (V_)   (_
'      Hyde       RR  RR   uuu uu  llll  zzzzzz   !!   !!    (V)(V)(V)   (V)(V)(V)
'                                                         My dog Smokey(Brainless Mutt)
'
' This code released under the GNU General Public License. This means you can use it,
' compile it, pass it around, modify it, WHATEVER! However, if you do this, I will
' expect notification and a copy of whatever you've done, unless it's a virus, or
' breaking into the CIA, etc. Also, there should be a prominent display in the program,
' visible to users, stating that I am responsible for that part of the program.
'                                                    Jeremiah "BJ" Hyde
' E-Mail me at: fishoffire@yahoo.com               fishoffire Industries:
'Visit me at: www.geocities.com/fishoffire/           Your source for
'                                                    EVERYTHING QBasic
'Note:
' This code has been tested on one machine(An AMD K6-266, 32MB RAM, 4.2GB HD, 15"
' PnP Monitor, Win95 DOS Box), and has run correctly there. However, no guarantee,
' warranty, or other declaration of safety, etc. is offered. If your computer system
' is taken over by smurfs, or the PROM is zapped, or anything else of a detrimental
' nature happens to your system as a result of this code, I am not responsible for
' it. The full burden of blame rests on your shoulders. (Of course, if something
' GOOD happens to your computer as a result of this code, well, obviously, I did it!)

' This module provides nearly drop-in replacements
' for VB's built-in registry manipulation.
' Copyright (c) 2000 Jeremiah "BJ" Hyde
'-------------------------------------------------
' Dependencies: Registry (Registry.Bas)
' Quirks: Almost no error handling as of 5/10/2000

Option Explicit

Public Sub SaveSetting(ByVal HKEY As HKEY_BASE, ByVal FullPath As String, ByVal Key As String, ByVal Setting)
Dim hOpenKey As Long
hOpenKey = RegOpenKey(HKEY, FullPath)
If IsNumeric(Setting) Then
    RegSetNumericValue hOpenKey, Key, CLng(Setting)
Else
    RegSetStringValue hOpenKey, Key, CStr(Setting)
End If
RegCloseKey hOpenKey
End Sub

Public Sub DeleteSetting(ByVal HKEY As HKEY_BASE, ByVal FullPath As String, Optional Key As String)
If Key = "" Then
    RegDeleteKey HKEY, FullPath
Else
    RegDeleteKey HKEY, FullPath & "\" & Key
End If
End Sub

Public Function GetAllSettings(ByVal HKEY As HKEY_BASE, ByVal FullPath As String) As Variant
Dim hOpenKey As Long, vntRet As Variant, lTmp As Long
ReDim vntRet(1, 1)
On Error Resume Next
hOpenKey = RegOpenKey(HKEY, FullPath)
If Err Then Exit Function
lTmp = -1
Do While Not Err = regEnumKeyErr
    lTmp = lTmp + 1
    RegEnumKey hOpenKey, lTmp
Loop
Err.Clear
ReDim vntRet(0 To lTmp - 1, 0 To 1)
For lTmp = 0 To lTmp - 1
    vntRet(lTmp, 0) = RegEnumKey(hOpenKey, lTmp)
    vntRet(lTmp, 1) = RegQueryStringValue(hOpenKey, vntRet(lTmp, 0))
    If Err Then
        Err.Clear
        vntRet(lTmp, 1) = RegQueryNumericValue(hOpenKey, vntRet(lTmp, 0))
        If Err Then GoTo QuitIt
    End If
Next
GetAllSettings = vntRet
QuitIt:
RegCloseKey hOpenKey
End Function

Public Function GetSetting(ByVal HKEY As HKEY_BASE, ByVal FullPath As String, ByVal Key As String, Optional ByVal Default As Variant) As Variant
Dim hOpenKey As Long, strTmp As String, lngTmp As Long
On Error Resume Next
hOpenKey = RegOpenKey(HKEY, FullPath)
If Err Then Exit Function
strTmp = RegQueryStringValue(hOpenKey, Key)
If Err Then
    Err.Clear
    lngTmp = RegQueryNumericValue(hOpenKey, Key)
    If Err Then GoTo QuitIt
    GetSetting = lngTmp
Else
    GetSetting = strTmp
End If
QuitIt:
RegCloseKey hOpenKey
End Function
