以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [原创]  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=196218)

--  作者:Cloud
--  发布时间:2025/4/9 18:09:00
--  [原创]
求大神指点:
     表格有20列,写一个公式将这20列中不为空的单元格数量计算后自动填入单元格中:比如:e.DataRow("积值") = e.DataRow("开号1") + e.DataRow("开号2") + e.DataRow("开号3")
这个积值=开号1,开号2,开号3中不为空的记录数

--  作者:Cloud
--  发布时间:2025/4/9 22:41:00
--  
Dim r1 = Tables("澳门六合表").Current("预号1")
If Tables("澳门六合表").Current("预号1") > 0 Then
    r1 = 1
    Dim r2 = Tables("澳门六合表").Current("预号2")
    If Tables("澳门六合表").Current("预号2") > 0 Then
        r2 = 1      
        Dim r3 = Tables("澳门六合表").Current("预号3")
        If Tables("澳门六合表").Current("预号3") > 0 Then
            r3 = 1
            Dim r4 = Tables("澳门六合表").Current("预号4")
            If Tables("澳门六合表").Current("预号4") > 0 Then
                r4 = 1
                Tables("澳门六合表").Current("计数") = r1 + r2 + r3 + r4
            End If
        End If
    End If
End If
这样写这个代码可以实现,但是有点复杂了,怎么写会简单一些,求大神指点一下 ,谢谢

--  作者:有点蓝
--  发布时间:2025/4/10 8:50:00
--  
Dim sum As Integer
Dim r As Row = Tables("澳门六合表").Current
If r IsNot Nothing Then
    For Each c As Col In Tables("澳门六合表").cols
        If c.name.StartsWith("预号") AndAlso r.isnull(c.name) = False Then
            sum += 1
        End If
    Next
    r("计数") = sum
End If

--  作者:Cloud
--  发布时间:2025/4/10 15:25:00
--  
谢谢