VBA Dictionary指定のキーがあるか真偽値を返す

環境
Windows 10 Home
Excel 2013
構文
ディクショナリ名.Exists(キー)
Existsを使って、Dictionaryに指定のキーが存在するか確認しています。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
Sub testark()
Dim city As Object
Set city = CreateObject("Scripting.Dictionary")
city.Add "ta", "東京"
city.Add "tb", "大阪"
city.Add "tc", "福岡"
If city.Exists("tb") = True Then
Debug.Print "キーtbが存在します"
End If
If city.Exists("td") = False Then
Debug.Print "キーtdが存在しません"
End If
End Sub
Sub testark() Dim city As Object Set city = CreateObject("Scripting.Dictionary") city.Add "ta", "東京" city.Add "tb", "大阪" city.Add "tc", "福岡" If city.Exists("tb") = True Then Debug.Print "キーtbが存在します" End If If city.Exists("td") = False Then Debug.Print "キーtdが存在しません" End If End Sub
Sub testark()

    Dim city As Object
    Set city = CreateObject("Scripting.Dictionary")

    city.Add "ta", "東京"
    city.Add "tb", "大阪"
    city.Add "tc", "福岡"

   If city.Exists("tb") = True Then
        Debug.Print "キーtbが存在します"
    End If

   If city.Exists("td") = False Then
        Debug.Print "キーtdが存在しません"
    End If

End Sub

実行結果
キーtbが存在します
キーtdが存在しません

VBScript

Posted by arkgame