読者です 読者をやめる 読者になる 読者になる

bekkou68の日記

開発しているサービス, IT技術, 英語など。

Collection の要素をイミディエイトウィンドウに表示する - Show Collection Items to Immediate Window

VBA

実装 - Implementation

' ===== Outline
' Show items of Collection to immediate window.
'
' ===== Argument
' colTarget: Collection, you'd like to show items.
'
' ===== Author
' bekkou68
Private Sub ShowCollection(ByVal colTarget As Collection)
    Dim varTarget As Variant
    Debug.Print "#Element: " & colTarget.Count
    For Each varTarget In colTarget
        Debug.Print varTarget
    Next
End Sub

テスト - Test

Option Explicit

Public Sub TestShowCollection()
    Debug.Print "- - - - -"
    Dim colHobby As Collection
    Set colHobby = New Collection
    With colHobby
        .Add ("reading books")
        .Add ("programming")
        .Add ("music appreciation")
        .Add ("waching niconico")
    End With
    Call ShowCollection(colHobby)
    Set colHobby = Nothing
    Debug.Print "- - - - -"
    Call ShowCollection(New Collection)
    Debug.Print "- - - - -"
End Sub

' ===== Outline
' Show items of Collection to immediate window.
'
' ===== Argument
' colTarget: Collection, you'd like to show items.
'
' ===== Author
' bekkou68
Private Sub ShowCollection(ByVal colTarget As Collection)
    Dim varTarget As Variant
    Debug.Print "#Element: " & colTarget.Count
    For Each varTarget In colTarget
        Debug.Print varTarget
    Next
End Sub


以下、イミディエイトウィンドウの出力。
The following is output of immediate window.

- - - - -
#Element: 4
reading books
programming
music appreciation
waching niconico
- - - - -
#Element: 0
- - - - -


うん、おk。
Now, good.


−ω−