Attribute VB_Name = "RegSettings"
Option Explicit

'Private Const sREG_PATH As String = "Software\Edcraft"
'Private Const sREG_PATH As String = "Software\Microsoft\Visual Basic\6.0"              ' VB IDE settings
'Private Const sREG_PATH As String = "Software\Microsoft\Visual Basic\6.0\Addins"       ' Registered addins
'Private Const sREG_PATH As String = "Software\Microsoft\Visual Basic\6.0\AddInToolbar" ' Addins in addin toolbar
'Private Const sREG_PATH As String = "Software\Microsoft\Visual Basic\6.0\RecentFiles"  ' Recently opened files ' (Str) 1 to n
'                  [HKEY_CURRENT_USER\Software\Microsoft\Visual Basic\6.0] MDIMaximized = 1
'Private Const sREG_PATH As String = "Software\Microsoft\VBA\Microsoft Visual Basic"    ' VB codepane settings
Private Const sREG_PATH As String = "Software\VB and VBA Program Settings"             ' Default path
Private Const sBK_SLASH As String = "\"

Public Sub SaveSetting(AppName As String, Section As String, Key As String, Setting As String)
    RegSetValue CURRENT_USER, sREG_PATH & sBK_SLASH & AppName & sBK_SLASH & Section, Key, Setting
End Sub

Public Function GetSetting(AppName As String, Section As String, Key As String, Optional Default As String) As String
    Dim sBuf As String
    RegGetValue CURRENT_USER, sREG_PATH & sBK_SLASH & AppName & sBK_SLASH & Section, Key, sBuf
    If LenB(sBuf) Then GetSetting = sBuf Else GetSetting = Default
End Function

Public Sub DeleteSetting(AppName As String, Optional Section As String, Optional Key As String)
    Dim sSubKey As String
    If LenB(AppName) = 0& Then Exit Sub
    If LenB(Section) Then
        sSubKey = sREG_PATH & sBK_SLASH & AppName & sBK_SLASH & Section
    Else
        sSubKey = sREG_PATH & sBK_SLASH & AppName
    End If
    If LenB(Key) Then
        RegDeleteValue CURRENT_USER, sSubKey, Key
    Else
        RegDeleteKey CURRENT_USER, sSubKey
    End If
End Sub

Public Function GetAllSettings(AppName As String, Section As String, ByRef saVals() As String) As Long
    GetAllSettings = RegGetAllValues(CURRENT_USER, sREG_PATH & sBK_SLASH & AppName & sBK_SLASH & Section, saVals)
End Function

' This module depends on the RegStrings.bas module
