向数组添加字典 [英] Adding a dictionary to array

查看:62
本文介绍了向数组添加字典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想浏览一下Excel中的列表并将值分配给字典.字典将被列入清单.直到列中的单元格为空,这才会发生.作为整个函数的结果,将返回字典数组.

I'd like to go through list in Excel and assign the values to dictionary. The the dictionary will be put into list. This will happen until the cells in the column are blank. As a result of entire function, the array of dictionaries will be returned.

 Function CreateArrayofDicts()
    Dim catlist As Variant
    Dim catparams() As Variant
    Dim ChartParamsDict As Dictionary
    Dim k As Long
    catlist = ArrayProblemsCat()

    i = 1

    Do Until IsEmpty(Cells(i, 1))
        Set ChartParamsDict = New Scripting.Dictionary
        For j = 0 To UBound(catlist)
            Debug.Print Cells(i, 1)
            If Cells(i, 1) = catlist(j) Then
                Debug.Print 5
                ChartParamsDict.Add Key:="Cells(1,2)", Item:=Cells(i, 2)
                ChartParamsDict.Add Key:="Cells(1,3)", Item:=Cells(i, 3)
                ChartParamsDict.Add Key:="Cells(1,4)", Item:=Cells(i, 4)

                ReDim Preserve catparams(k)
                catparams(k) = ChartParamsDict ' issues is here
                k = k + 1
                Debug.Print ChartParamsDict
            End If

        Next j



    i = i + 1
    Loop
    CreateArrayofDicts = catparams
End Function

推荐答案

您在问题行上缺少 Set .

Set catparams(k) = ChartParamsDict

这篇关于向数组添加字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆