在 VBA 中模仿 std::map<string、std::list<string> >

Mimic std::map<string, std::list<string> > in VBA

本文关键字:std string lt gt list map VBA      更新时间:2023-10-16

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

我发现相当于std::map将是一个Dictionary,但是最后一部分呢?

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

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 ?!
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