Dictionary 객체 내의 지정된 키에 대한 항목을 설정하거나 반환합니다. 컬렉션의 경우 지정된 키에 따라 항목을 반환합니다. 읽기/쓰기.
구문
object.Item(key)[ = newitem]
인수:
Object: 필수. 항상 컬렉션 또는 Dictionary 객체의 이름입니다.
Key: 필수. 검색 중이거나 추가 중인 항목과 연계된 키입니다.
Newitem: 선택사항. Dictionary 객체에만 사용되며, 컬렉션에는 적용되지 않습니다. 제공되는 경우 newitem은 지정된 키와 연계된 새 값입니다.
주석
항목을 변경할 때 키를 찾을 수 없으면 지정된 newitem을 사용하여 새 키가 생성됩니다. 기존 항목을 반환할 때 키를 찾을 수 없으면 새 키가 생성되고 해당 항목은 비어 있습니다.
다음 예에서는 Item 등록정보의 사용을 보여줍니다.
예 1:
Function GetItem
Dim d ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "a", "Athens"
d.Add "b", "Belgrade"
d.Add "c", "Cairo"
' Get the item for key "c".
GetItem = d.Item("c")
End Function
' Usage
Dim result
result = GetItem()
' Output: Cairo
예 2:
Function SetExistingItem
Dim d ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "x", "Xenon"
d.Add "y", "Yttrium"
d.Add "z", "Zirconium"
' Set a new item for key "y".
d.Item("y") = "Yosemite"
' Get the item for key "y".
SetExistingItem = d.Item("y")
End Function
' Usage
Dim result
result = SetExistingItem()
' Output: Yosemite
예 3:
Function AddNewItem
Dim d ' Create some variables.
Set d = CreateObject("Scripting.Dictionary")
' Add some keys and items.
d.Add "m", "Moscow"
d.Add "n", "New York"
d.Add "t", "Tokyo"
' Attempt to get an item for a non-existing key and set a new item.
d.Item("p") = "Paris"
' Get the item for the newly added key "p".
AddNewItem = d.Item("p")
End Function
' Usage
Dim result
result = AddNewItem()
' Output: Paris