La méthode RemoveAll enlève toutes les paires clé/élément d'un objet Dictionary.
Syntaxe
object.RemoveAll( )
Arguments
object : requis. Toujours le nom d'un objet Dictionary.
Remarques
Les exemples de code suivants illustrent l'utilisation de la méthode RemoveAll :
Exemple 1 :
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "a", "Athens"
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
' Clear the dictionary
d.RemoveAll
' Output: Dictionary Object is empty.
Exemple 2 :
Function ClearDictionary
Dim d ' Create a variable.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "x", "Xenon"
d.Add "y", "Yttrium"
d.Add "z", "Zirconium"
' Clear the dictionary
d.RemoveAll
' Check if the dictionary is empty
If d.Count = 0 Then
ClearDictionary = "Dictionary has been cleared."
Else
ClearDictionary = "Dictionary is not empty."
End If
End Function
' Usage
Dim result
result = ClearDictionary
' Output: Dictionary has been cleared.
Exemple 3 :
Function ManageDictionary
Dim d, msg ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "m", "Moscow"
d.Add "n", "New York"
d.Add "p", "Paris"
' Remove a specific key
d.Remove("n")
' Display the items before clearing
msg = "Items before clearing:"
For Each Key In d.Keys
msg = msg & "Key: " & Key & ", Item: " & d.Item(Key)
Next
' Clear the dictionary
d.RemoveAll
' Check if the dictionary is empty
If d.Count = 0 Then
msg = msg & "Dictionary has been cleared."
Else
msg = msg & "Dictionary is not empty."
End If
ManageDictionary = msg
End Function
' Usage
Dim result
result = ManageDictionary
' Output: Items before clearing: Key: m, Item: Moscow Key: p, Item: Paris Dictionary has been cleared.