更改 VBA 中的嵌套字典
Changing nested dictionary in VBA
当解决方案出现在一次测试中时,我正要问一个问题。所以我还是发帖和回答,这样其他人也可以受益。
问题是:
我 运行 下面的代码并得到一个 运行 时间错误 450 - 错误的参数数量或无效的 属性 赋值
Dim data, tmpDict As Dictionary
Set data = New Dictionary
Set tmpDict = New Dictionary
data.Add 123, tmpDict
Set tmpDict = data.Item(123)
tmpDict.Add "somekey", 100
data.Item(123) = tmpDict
错误发生在最后一行。代码已简化,专注于更改现有项目中的嵌套字典。
我怎样才能成功?
该解决方案可以在 1 中收缩最后 3 行,使用:
data.Item(123).Add "somekey", 100
而不是:
Set tmpDict = data.Item(123)
tmpDict.Add "somekey", 100
data.Item(123) = tmpDict
当解决方案出现在一次测试中时,我正要问一个问题。所以我还是发帖和回答,这样其他人也可以受益。
问题是:
我 运行 下面的代码并得到一个 运行 时间错误 450 - 错误的参数数量或无效的 属性 赋值
Dim data, tmpDict As Dictionary
Set data = New Dictionary
Set tmpDict = New Dictionary
data.Add 123, tmpDict
Set tmpDict = data.Item(123)
tmpDict.Add "somekey", 100
data.Item(123) = tmpDict
错误发生在最后一行。代码已简化,专注于更改现有项目中的嵌套字典。
我怎样才能成功?
该解决方案可以在 1 中收缩最后 3 行,使用:
data.Item(123).Add "somekey", 100
而不是:
Set tmpDict = data.Item(123)
tmpDict.Add "somekey", 100
data.Item(123) = tmpDict