Count 메소드

collection 또는 Dictionary 객체의 항목 수를 반환합니다. 읽기 전용입니다.

구문

object.Count

인수

Object: 필수. 항상 Dictionary 객체의 이름입니다.

주석

다음 코드는 Count 등록정보의 사용을 보여줍니다.

예 1:

Function ShowItemCount
    Dim d, count
    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 count.
    count = d.Count

    ShowItemCount = "The dictionary contains " & count & " items."
End Function

' Usage
Dim result
result = ShowItemCount
' Output: The dictionary contains 3 items.

예 2:

Function DisplayItemsWithCount
    Dim d, i, s
    Set d = CreateObject("Scripting.Dictionary")

    ' Add some keys and items.
    d.Add "x", "Xenon"
    d.Add "y", "Yttrium"
    d.Add "z", "Zirconium"

    ' Get the item count.
    Dim count
    count = d.Count

    ' Display each item.
    s = "The dictionary contains " & count & " items:"
    For Each Key In d.Keys
        s = s & "Key: " & Key & ", Item: " & d.Item(Key)
    Next

    DisplayItemsWithCount = s
End Function

' Usage
Dim result
result = DisplayItemsWithCount
' Output: The dictionary contains 3 items: Key: x, Item: Xenon Key: y, Item: Yttrium Key: z, Item: Zirconium

예 3:

Function CountAfterRemoval
    Dim d, count, s
    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 key-item pair.
    d.Remove("n")

    ' Get the item count.
    count = d.Count

    ' Display the count and remaining items.
    s = "After removal, the dictionary contains " & count & " items:"
    For Each Key In d.Keys
        s = s & "Key: " & Key & ", Item: " & d.Item(Key)
    Next

    CountAfterRemoval = s
End Function

' Usage
Dim result
result = CountAfterRemoval
' Output: After removal, the dictionary contains 2 items: Key: m, Item: Moscow Key: p, Item: Paris