LoginSignup
0
1

More than 5 years have passed since last update.

vba【多次元のdictionaryにキーが存在するかを調べる】

Last updated at Posted at 2018-10-20

phpのissetのようなもの
vbaにはないので作りました。

Public Function isset(ByRef dic As Dictionary, ByVal KeyArr As Variant, Optional ByVal StartIndex As Integer) As Boolean
    On Error GoTo handler
    If dic.Exists(KeyArr(StartIndex)) Then
        If UBound(KeyArr) = StartIndex Then
            isset = True
        Else
            isset = isset(dic(KeyArr(StartIndex)), KeyArr, StartIndex + 1)
        End If
    Else
        isset = False
    End If
    Exit Function

handler:
    isset = False
End Function

呼び出し方

Private Sub testisset()
    Dim a As New Dictionary
    a.Add "b", New Dictionary
    a("b").Add "c", New Dictionary
    Debug.Print isset(a, Array("b", "c")) ' true
    Debug.Print isset(a, Array("b", "c", "d")) ' false
End Sub


0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1