Rss & SiteMap

Foxtable(狐表) http://www.foxtable.com

新一代数据库软件,完美融合Access、Foxpro、Excel、vb.net之优势,人人都能掌握的快速软件开发工具!
共3 条记录, 每页显示 10 条, 页签: [1]
[浏览完整版]

标题:字典中多字段字段计算

1楼
creastzh 发表于:2025/5/11 15:07:00
字典中多字段字段计算

老师,我有一个字典的使用问题请教, 问题是这样的:
   我有以Item为Key值的多个字段A,B,C,D需要求和, 因此写了程序:
   dim d as new dictionary (of string, Integer())
 
for each dr as datarow in drs
 if not d.contains(dr("Item")) then
d.add(dr("item"), dr("a"),dr("b"),dr("c"),dr("d"))   '这里就报错了
else
d.remove(dr("Item"))
d.add(dr("Item"),d(dr("Item"))(0)+dr("a"),d(dr("Item"))(1)+dr("b"),d(dr("Item"))(2)+dr("c"),d(dr("Item"))(3)+dr("d")) '
end if
next 

这里怎么都调试通不过, 有什么办法吗? 还有是否一定要先使用 d.remove(xx)方式重新赋值? 有没有简单一些的方式, 谢谢!





2楼
有点蓝 发表于:2025/5/11 19:28:00
d.add(dr("item"), {dr("a"),dr("b"),dr("c"),dr("d")}) 

或者

dim tmp() as Integer = {dr("a"),dr("b"),dr("c"),dr("d")}
d.add(dr("item"), tmp
3楼
y2287958 发表于:2025/5/12 9:21:00
例如:
Dim d As New dictionary (Of String, Integer()) From {{"A", {11, 22, 33, 44}}}
Dim 数组() As Integer = {1, 2, 3, 4}
Dim 字典键名 As String = "A1"
d(字典键名) = ({数组(0) + d("A")(0), 数组(1) + d("A")(1), 数组(2) + d("A")(2), 数组(3) + d("A")(3)})
For Each k As String In d.Keys 
    Output.Show (String.join(",", d(k)))
Next 
共3 条记录, 每页显示 10 条, 页签: [1]

Copyright © 2000 - 2018 foxtable.com Tel: 4000-810-820 粤ICP备11091905号

Powered By Dvbbs Version 8.3.0
Processed in .04688 s, 2 queries.