gpt4 book ai didi

excel - 更改 VBA 字典中的数组值

转载 作者:行者123 更新时间:2023-12-01 22:32:23 35 4
gpt4 key购买 nike

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

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

最佳答案

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

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

关于excel - 更改 VBA 字典中的数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2404212/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com