【问题标题】:Mimic std::map<string, std::list<string> > in VBA在 VBA 中模仿 std::map<string, std::list<string>>
【发布时间】:2012-06-17 23:17:18
【问题描述】:

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

我发现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 ?!

【问题讨论】:

    标签: c++ arrays vba dictionary


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-22
      • 2011-03-26
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多