vba_array


'-----------------------------------------------------------------------------------------------------------------------
' Auteur        : pascalterheege.nl
' Datum         : 10-1-2020
' Doel          : array vs dictionary vs collection
' Opmerking     : verwijzing Microsoft Scripting Runtime (dictionary)
' Bron          : https://excelmacromastery.com/vba-dictionary
'-----------------------------------------------------------------------------------------------------------------------

Sub Arr()

    Dim a() As Variant
    
    Dim r As Integer
    Dim k As Integer
    
    For r = 0 To 5
    
        For k = 0 To 2
        
            ReDim Preserve a(2, r)
            
            a(k, r) = k & "+" & r
            
            Debug.Print a(k, r)
        
        Next k
    
    Next r
    
    Debug.Print "-------------------------------------------"
    
    For r = LBound(a, 2) To UBound(a, 2)        ' dimension 2 = r

        For k = LBound(a, 1) To UBound(a, 1)    ' dimension 1 = k

            Debug.Print a(k, r)

        Next k

    Next r
   
End Sub

Sub Dict()

    Dim d As New Scripting.Dictionary
    Dim key As Variant
    
    d.Add key:="Appel", item:=0
    d.Add key:="Peer", item:=2
    d.Add key:="Mandarijn", item:=3
        
    If d.Exists("Appel") Then d("Appel") = 1
    d.Remove "Mandarijn"
        
    For Each key In d.Keys
    
        MsgBox key & ":" & d(key)
    
    Next key
    

End Sub

Sub Col()

    Dim c As New Collection
    Dim item As Variant
        
    c.Add key:="Appel", item:=1
    c.Add key:="Peer", item:=2
    c.Add key:="Mandarijn", item:=3
        
    For Each item In c
    
        MsgBox item
    
    Next item

End Sub