以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]请教计算每行的问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=173475) |
-- 作者:nevercool -- 发布时间:2021/12/1 11:17:00 -- [求助]请教计算每行的问题 For Each dr As DataRow In DataTables("表A").DataRows Dim n As Double For Each dc As DataCol In DataTables("表A").DataCols If dc.IsNumeric AndAlso dc.Name <> "总分" Then n = n + dr(dc.Name) End If dr("总分") = n Next Next 在命令窗口执行计算每行的总分值,应该怎么写
|
-- 作者:有点蓝 -- 发布时间:2021/12/1 11:30:00 -- For Each dr As DataRow In DataTables("表A").DataRows Dim n As Double = 0 For Each dc As DataCol In DataTables("表A").DataCols If dc.IsNumeric AndAlso dc.Name <> "总分" Then n = n + dr(dc.Name) End If Next dr("总分") = nNext
|
-- 作者:nevercool -- 发布时间:2021/12/1 11:53:00 -- OK! 不过Double默认值不也是0么,应该怎么去正确理解呢 |
-- 作者:有点蓝 -- 发布时间:2021/12/1 12:13:00 -- 这个涉及到变量的可用域问题,如果不每次初始化值,那么循环内定义的变量是每个循环都可以使用的,自己测试一下 For i As Integer = 1 To 10 Dim n As Double For j As Integer = 1 To 5 n = n + j Next Output.Show(n) Next 和 For i As Integer = 1 To 10 Dim n As Double = 0 For j As Integer = 1 To 5 n = n + j Next Output.Show(n) Next |