更改 VBA 字典中的数组值 [英] Changing array values in a VBA dictionary

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

问题描述

我有一段代码似乎没有按预期执行.VBA 数组无论如何都是可变的,但似乎当它们作为某些键的值存储到字典中时,它们就不再可变了.有什么想法吗?

I have a piece of code that does not seem to do what it is expected to do. VBA Arrays are mutable by all means, but it seems that when they are stored into a Dictionary as values of some keys, they are not mutable anymore. Any ideas?

Sub foo()
    Dim mydict As New Dictionary
    mydict.Add "A", Array(1, 2, 3)
    MsgBox mydict("A")(1)
    ''# The above shows 2, which is fine
    mydict("A")(1) = 34
    MsgBox mydict("A")(1)
    ''# The above also shows 2, which is not fine
End Sub

推荐答案

看来您还需要设置另一个变量来更新数组值.

It seems you'll need yet to set another var to update the array value.

mArray = mydict.Item(1)
mArray(1) = 34
mydict.Item(1) = mArray

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

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