我有一本字典,其中用学校名称作为键和值的数组。一旦将键值对添加到字典中,我希望能够在检查是否满足某些条件后更新数组的值。但是,即使满足条件,值也不会更新。有什么想法吗?

Dim nre(0 To 2) As Boolean
nre(0) = False
nre(1) = False
nre(2) = False

Dim schdict
Set schdict = CreateObject("Scripting.Dictionary")

For i = 2 To numrows
    schname = ActiveSheet.Cells(i, schnamecolumn).Value
    category = ActiveSheet.Cells(i, categorycolumn).Value
    If schdict.Exists(schname) = False Then
        schdict.Add schname, nre
    End If

    If category = "New Placement" Then
        schdict.Item(schname)(0) = True
    ElseIf category = "Renomination" Then
        schdict.Item(schname)(1) = True
    Else
        schdict.Item(schname)(2) = True
    End If
Next i

MsgBox schdict.Item("Division 01")(0)

最佳答案

试试这个:

创建第二个数组:

Dim vArray as variant

redim vArray(0 to 2)


然后将字典数组分配给新创建的数组,如下所示:

vArray = schdict.Item(schname)


设置数组的值:

vArray(1) = True


最后将数组分配给字典项:

schdict.Item(schname) = vArray

07-27 13:46