pgbigorokuのブログ

プログラムの再利用できそうなコードをアップ

EXCEL VBA ディクショナリーただそれだけ(作成中)

Option Explicit

'ディクショナリーただそれだけ
'(tagもitemもString型のみ)
'
'作成中 2022/8/14

Dim pdic As Object

Private Sub Class_Initialize()
    Set pdic = CreateObject("Scripting.Dictionary")
End Sub

Public Function Add(ByVal pstrTag As String, ByVal pstrItem As String) As Boolean
    If pdic.Exists(pstrTag) = True Then
        Add = False
    Else
        Call pdic.Add(pstrTag, pstrItem)
        Add = True
    End If
End Function

Public Function Exists(ByVal pstrTag As String)
    Exists = pdic.Exists(pstrTag)
End Function


Public Function Item(ByVal pstrTag As String) As String
    If pdic.Exists(pstrTag) = True Then
        Items = pdic.Item(pstrTag)
    Else
        Item = ""
    End If
End Function

Public Function Remove(ByVal pstrTag As String) As Boolean
    If pdic.Exists(pstrTag) = True Then
        Remove = pdic.Remove(pstrTag)
        Remove = True
    Else
        Remove = False
    End If
End Function


Public Function RemoveAll()
    pdic.RemoveAll
End Function

Property Get Count() As Integer
    Count = pdic.Count
End Property