サーチ…


辞書の作成と辞書への項目の追加

Dim oDic
Set oDic = CreateObject("Scripting.Dictionary")
oDic.Add "US", "United States of America"
oDic.Add "UK", "United Kingdom"

辞書にキーが存在するかどうかを確認する

If oDic.Exists("US") Then
    msgbox "The Key US Exist. The value is " + oDic("US")
Else
    msgbox "Key Does not exist."
End If 

辞書から項目を削除する

If oDic.Exists("UK") Then
    oDic.remove("UK")
End If

辞書内のすべての項目を繰り返します。

set oDic = CreateObject("Scripting.Dictionary")
oDic.add "USA", "United States of America"
oDic.add "UK", "United Kingdom"
oDic.add "CAN", "Canada"

For Each obj in oDic.Items
    Msgbox obj
Next
Set oDic = Nothing

* 出力:

アメリカ合衆国

イギリス

カナダ

辞書内のすべてのキーを繰り返します。

set oDic = CreateObject("Scripting.Dictionary")
oDic.add "USA", "United States of America"
oDic.add "UK", "United Kingdom"
oDic.add "CAN", "Canada"

For Each obj in oDic.keys
    Msgbox "Key: " & obj & " Value: " & oDic(obj)
Next
Set oDic = Nothing

辞書からキー/キーを削除する

set oDic = CreateObject("Scripting.Dictionary")
oDic.add "USA", "United States of America"
oDic.add "UK", "United Kingdom"
oDic.add "CAN", "Canada"

' Delete only if Key exists
If oDic.Exists("UK") Then
    oDic.Remove "UK"
End If    

' Delete all keys from Dictionary
oDic.removeAll 

Set oDic = Nothing


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow