gpt4 book ai didi

vba - 如何覆盖 scripting.dictionary 中键的值?

转载 作者:行者123 更新时间:2023-12-04 21:20:48 24 4
gpt4 key购买 nike

我在 for 循环中嵌套了以下 if 子句:

    If status Like "*Active*" Then
total_active = total_active + amount
On Error Resume Next
active_dict.Add Key:=cost_center, Item:=total_active
On Error GoTo 0
end if
On Error Resume Next用于忽略 active_dict 中已存在的键时的错误字典正在被添加到它。

问题是 key ( total_active ) 的值 ( cost_center ) 没有更新。

问题是:是否可以覆盖字典键的值?

最佳答案

如果您使用 Microsoft 脚本字典,则可以使用以下内容:

If status Like "*Active*" Then
total_active = total_active + amount
If active_dict.Exists(cost_center) Then
active_dict(cost_center) = total_active
Else
active_dict.Add Key:=cost_center, Item:=total_active
End If
End If

甚至更好(参见 Kostas K 评论):
If status Like "*Active*" Then
total_active = total_active + amount
active_dict(cost_center) = total_active
End If

关于vba - 如何覆盖 scripting.dictionary 中键的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50585256/

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