Dictionary 객체에 키 및 항목 쌍을 추가합니다.
구문
object.Add(key, item)
인수:
Object: 필수. 항상 Dictionary 객체의 이름입니다.
Key: 필수. 추가할 항목과 연계된 키입니다.
Item: 필수. 추가할 키와 연계된 항목입니다.
주석
키가 이미 있으면 오류가 발생합니다.
다음 예에서는 Add 메소드의 사용을 보여 줍니다.
예 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"
' Output: Dictionary Object Contains Keys: a,b,c Items: Athens,Belgrade,Cairo
예 2:
Dim d
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
If Not d.Exists("a") Then
d.Add "a", "Athens"
End If
If Not d.Exists("b") Then
d.Add "b", "Belgrade"
End If
If Not d.Exists("c") Then
d.Add "c", "Cairo"
End If
' Output: Dictionary Object Contains Keys: a,b,c Items: Athens,Belgrade,Cairo
예 3:
Dim d
Set d = CreateObject("Scripting.Dictionary")
Dim arrKeys, arrItems
arrKeys = Array("a", "b", "c")
arrItems = Array("Athens", "Belgrade", "Cairo")
For i = 0 To UBound(arrKeys)
d.Add arrKeys(i), arrItems(i)
Next
' Output: Dictionary Object Contains Keys: a,b,c Items: Athens,Belgrade,Cairo
Note:
딕셔너리 추가 호출에서 새 객체 생성 직접 사용은 지원되지 않습니다.
예:
Set d = CreateObject("Scripting.Dictionary")
'먼저 객체를 생성한 다음 딕셔너리에 추가합니다.
Set obj = new class
d.add key, obj 이 기능은 지원됩니다.