VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "PropBag"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Data As Collection

Public Sub Create()
Debug.Assert Data Is Nothing
Set Data = New Collection
End Sub

Public Function ReadIn(File As String) As Boolean
Create

Dim FileNo As Integer
FileNo = FreeFile()
On Error GoTo Failure
    Open File For Input As #FileNo
On Error GoTo 0

Dim Buffer As String, pi As PropItem, i As Integer
Do While Not EOF(FileNo)
    Line Input #FileNo, Buffer
    If Buffer <> "" Then
        Set pi = New PropItem
        pi.ReadIn Buffer
        Data.Add pi, pi.Key
    End If
Loop

ReadIn = True
Close #FileNo

Failure:
End Function

Public Sub WriteOut(File As String)
Dim FileNo As Integer
FileNo = FreeFile()
On Error GoTo Failure
    Open File For Output As #FileNo
On Error GoTo 0

Dim pi As PropItem, s As String
For Each pi In Data
    s = pi.WriteOut
    If s <> "" Then Print #FileNo, s
Next
Exit Sub

Failure:
MsgBox "Could not write to the file '" + File + "'" + vbNewLine + Err.Description, vbCritical
End Sub

Public Function GetVal(Key As String, Optional Default As String = "") As String
Dim pi As PropItem
On Error GoTo Failure
    Set pi = Data(Key)
On Error GoTo 0

GetVal = pi.Value
Exit Function

Failure:
GetVal = Default
End Function

Public Property Let SetVal(Key As String, Value As String)
Dim pi As PropItem
On Error GoTo Failure
    Set pi = Data(Key)
On Error GoTo 0

pi.Value = Value
Exit Property

Failure:
Add Key, Value
End Property

Public Sub Add(Key As String, Value As String)
Dim pi As PropItem
Set pi = New PropItem
pi.Key = Key
pi.Value = Value
Data.Add pi, Key
End Sub

