【问题标题】:Accessing dictionary in the array访问数组中的字典
【发布时间】:2020-05-16 21:53:46
【问题描述】:

我创建了一个返回字典数组的函数 CreateArrayOfDicts()。现在我正在努力访问另一个子中的字典。如何访问其中一个字典,尤其是每个字典中专用键下的值?

'类别'

是字典中的键之一

 Sub EditDataSeriesParams()
    Dim mySeries As Series
    Dim key As Variant
    catparams = CreateArrayofDicts() ' array of dictionaries
    Dim ws As Worksheet
    Set ws = Sheets("Sheet1")

    i = 7
    'Debug.Print ws.Cells(7, 21)

    Do Until IsEmpty(ws.Cells(i, 21))
        For Each mySeries In ActiveSheet.ChartObjects("Test").Chart.SeriesCollection
            For j = 0 To UBound(catparams) 'entering array of dictionaries
                If ws.Cells(i, 21) = mySeries.Name And catparams(j).("Category") = mySeries.Name Then ' issue is here
                    mySeries.Select
                    Debug.Print 5
                    With Selection
                        .MarkerStyle = xlMarkerStyleTriangle
                        .MarkerSize = catparams(j)("Size") ' Size is a key in dict
                        .MarkerBackgroundColor = catparams(j)("Back") ' Back is a key in dict
                        .MarkerForegroundColor = catparams(j)("Front") ' Front is a key in dict

                    End With

                End If

            Next j
        Next mySeries

    i = i + 1
    Loop
End Sub

【问题讨论】:

标签: arrays vba dictionary


【解决方案1】:

尝试不带点,就像您随后在代码中所做的那样...

catparams(j)("Category") = mySeries.Name

【讨论】:

    猜你喜欢
    • 2015-01-10
    • 1970-01-01
    • 2014-03-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-04
    • 2013-10-06
    • 1970-01-01
    相关资源
    最近更新 更多