Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am trying to mimic std::map<string, std::list<string> > in VBA (this case is very specific, but really any collection inside a nstd::map<>-like container)

I have found that the equivalent of std::map would be a Dictionary, but how about the last part?

Somehow the most I've found on the internet is that it is possible to add an array element like this to a Dictionary, though without any insight as to how to add elements AFTER this has been done:

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 ?!
like image 351
ApplePie Avatar asked Jul 30 '26 05:07

ApplePie


1 Answers

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
like image 172
Tim Williams Avatar answered Jul 31 '26 20:07

Tim Williams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!