我正在尝试在VBA中模仿std::map<string, std::list<string> >
(这种情况非常具体,但实际上是n std::map<>
中的任何集合 - 类似容器)
我发现std::map
的等价物是Dictionary
,但最后一部分怎么样?
我在互联网上找到的最多的是,可以将这样的数组元素添加到Dictionary
,但是如果在完成此操作后如何添加元素,则无需任何见解:< / p>
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 ?!
答案 0 :(得分: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