以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]不同表对应列计算并合计  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=171883)

--  作者:lgj716330
--  发布时间:2021/9/13 19:53:00
--  [求助]不同表对应列计算并合计

图片点击可在新窗口打开查看此主题相关图片如下:0913.png
图片点击可在新窗口打开查看
如图,如何实现表2的每行的每一列乘以表1对应的每列,然后合计在表2的“合计”列

--  作者:有点蓝
--  发布时间:2021/9/13 20:19:00
--  
参考:http://www.foxtable.com/webhelp/topics/1451.htm
--  作者:lgj716330
--  发布时间:2021/9/13 21:34:00
--  
两张都是统计生成的表,而且列数不固定,有点晕
--  作者:有点蓝
--  发布时间:2021/9/13 21:55:00
--  
一样遍历所有列处理。
--  作者:lgj716330
--  发布时间:2021/9/13 23:07:00
--  
Dim dic As new Dictionary(of String, String)
Dim Lst As New List(Of Integer)
For Each dc As Col  In Tables("结算_Table2").cols
    If dc.name<>"工厂" And dc.name<>"姓名" And dc.name<>"合计" Then
        dic.add(dc.Caption, dc.name)
        Lst.Add(dc.Caption)
    End If
Next

Dim dic1 As new Dictionary(of String, String)
Dim Lst1 As New List(Of Integer)
For Each dc As Col  In Tables("结算_Table1").cols
    If dc.name<>"工厂" And dc.name<>"款号" And dc.name<>"合计" Then
        dic1.add(dc.Caption, dc.name)
        Lst1.Add(dc.Caption)
    End If
Next

Dim sm As Double
For Each r As Row In Tables("结算_Table2").Rows
    For Each r1 As Row In Tables("结算_Table1").Rows
        For i As Integer = Lst.count-1 To 0 Step -1
            sm = r(dic(Lst(i)))*r1(dic1(Lst1(i)))
            r("合计") = r("合计")+sm
        Next    
    Next
Next

按一次会累加一次,不知怎么退出
[此贴子已经被作者于2021/9/13 23:48:19编辑过]

--  作者:lgj716330
--  发布时间:2021/9/14 0:01:00
--  
Dim sm As Double
For Each r As Row In Tables("结算_Table2").Rows
    r("合计") = Nothing
    For Each r1 As Row In Tables("结算_Table1").Rows
        For i As Integer = Lst.count-1 To 0 Step -1
            sm = r(dic(Lst(i)))*r1(dic1(Lst1(i)))
            r("合计") = r("合计")+sm
        Next    
    Next
Next