是否可以有多个字典自动将以相同数字结尾的键添加到其中?
我的想法是这样的:
dicInfo (i). add (key (i), value)
那么,当有诸如key1,key2,key3之类的键时,它们是否被添加到dicInfo1,dicInfo2等?
谢谢!
答案 0 :(得分:1)
这里是将字典添加到字典并返回值的方法
Sub Demo()
Dim dic As Object, key As Variant
Dim j As Long
Set dic = CreateObject("Scripting.Dictionary")
For j = 1 To 100
key = CLng(Right(j, 1))
If Not dic.Exists(key) Then dic.Add key:=key, Item:=CreateObject("Scripting.Dictionary")
dic(key).Add dic(key).Count, j
Next
For j = 0 To 9
Debug.Print Join(dic(j).Keys(), ",")
Debug.Print Join(dic(j).Items(), ",")
Next
End Sub