Method: Exists for Dictionary
- Updated2024-09-12
- 1 minute(s) read
FileSystemObject and Dictionary > Methods > Method: Exists for Dictionary
Method: Exists for Dictionary
Checks whether there is a key in a Dictionary collection.
bExists = Object.Exists(Key)
| Object | Dictionary Object with this method |
| Key | Variant Specifies the key. |
| bExists | Boolean If the key exists, the value is True. If the key does not exist, the value is False. |
The following example generates a Dictionary collection and adds some key/element pairs. Then the example checks whether the key "a" exists:
Dim MyDic Set MyDic = CreateObject("Scripting.Dictionary") Call MyDic.Add ("a", "Austin") Call MyDic.Add ("b", "Berlin") Call MyDic.Add ("c", "Chicago") If MyDic.Exists("a") Then Call MsgBox("Key 'a' already exists") Else Call MyDic.Add ("a", "Aachen") End If