3

我正在尝试std::map<string, std::list<string> >在 VBA 中进行模仿(这种情况非常具体,但实际上是在类似std::map<>容器中的任何集合)

我发现相当于std::mapa Dictionary,但最后一部分呢?

不知何故,我在互联网上发现的最多的是可以将这样的数组元素添加到 aDictionary中,尽管没有任何关于如何在完成后添加元素的见解:

Dim my_dictionary as Dictionary
Set my_dictionary = New Dictionary
my_dictionary.Add "KEY#1", Array("A", "B", "C")
'How would I add "D" here ?!
4

1 回答 1

3
Sub Tester()

    Dim d As Scripting.Dictionary
    Dim arr, ub

    Set d = New Scripting.Dictionary

    d.Add "key1", Array("A", "B", "C")

    Debug.Print Join(d("key1"))

    arr = d("key1")
    ub = UBound(arr) + 1
    ReDim Preserve arr(0 To ub)
    arr(ub) = "D"
    d("key1") = arr

    Debug.Print Join(d("key1"))

End Sub
于 2012-06-14T21:43:47.677 回答