求大神指点:
表格有20列,写一个公式将这20列中不为空的单元格数量计算后自动填入单元格中:比如:e.DataRow("积值") = e.DataRow("开号1") + e.DataRow("开号2") + e.DataRow("开号3")
这个积值=开号1,开号2,开号3中不为空的记录数
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
这样写这个代码可以实现,但是有点复杂了,怎么写会简单一些,求大神指点一下 ,谢谢
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