Suche…


Erstellen Sie ein Wörterbuch und fügen Sie dem Wörterbuch Elemente hinzu

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

Prüfen Sie, ob der Schlüssel im Wörterbuch vorhanden ist

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

Artikel aus dem Wörterbuch entfernen

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

Alle Elemente im Wörterbuch iterieren

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

* Ausgabe:

vereinigte Staaten von Amerika

Großbritannien

Kanada

Iteriere alle Schlüssel im Wörterbuch

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

Schlüssel / Schlüssel aus dem Wörterbuch löschen

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
Lizenziert unter CC BY-SA 3.0
Nicht angeschlossen an Stack Overflow