Foxtable(狐表)用户栏目专家坐堂 → [求助]代码简化


  共有3274人关注过本帖树形打印复制链接

主题:[求助]代码简化

帅哥哟,离线,有人找我吗?
cqlpjks
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:407 积分:3194 威望:0 精华:0 注册:2011/2/28 11:57:00
[求助]代码简化  发帖心情 Post By:2021/2/20 14:15:00 [只看该作者]

Dim fhs() As String = {"德","能","勤","绩","廉"}
Dim pj2s() As String = {"好","较好","一般","差"}
Dim djs() As String = {"A","B","C","D"}
Dim dlqjs() As String = {"题号1","题号2","题号3","题号4","题号5"}
For Each fh As String In fhs
  For Each dlqj As String In dlqjs
    For i As Integer = 1 To 5
      For j As Integer = 0 To djs.length - 1
         dr("德" & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr("题号1") &")", "" & dr("题号1") & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
         dr("能" & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr("题号2") &")", "" & dr("题号2") & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
         dr("勤" & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr("题号3") &")", "" & dr("题号3") & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
         dr("绩" & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr("题号4") &")", "" & dr("题号4") & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
         dr("廉" & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr("题号5") &")", "" & dr("题号5") & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
         Next
      Next
   Next
Next
红色代码简化成:
dr(fh & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr(dlqjs(j)) &")", "" & dr(dlqjs(j)) & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
统计结果全是最后一个红色代码dr("廉" & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr("题号5") &")", "" & dr("题号5") & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")的结果。

图片点击可在新窗口打开查看此主题相关图片如下:统计结果.png
图片点击可在新窗口打开查看
不知问题在哪,如何修改代码?请指教,谢谢!


[此贴子已经被作者于2021/2/20 14:27:03编辑过]

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111414 积分:567140 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/2/20 14:30:00 [只看该作者]

Dim fhs() As String = {"德","能","勤","绩","廉"}
Dim pj2s() As String = {"好","较好","一般","差"}
Dim djs() As String = {"A","B","C","D"}
Dim dlqjs() As String = {"题号1","题号2","题号3","题号4","题号5"}
For i As Integer = 0 To fhs.length - 1
      For j As Integer = 0 To djs.length - 1
         dr(fhs(i) & djs(j) & "人") = DataTables("答案1").Compute("Count("& dr(dlqjs(i)) &")", "" & dr(dlqjs(i)) & " = '"& djs(j) &"' And [单位] = '" & dr("单位") & "'")
      Next
Next

 回到顶部
帅哥哟,离线,有人找我吗?
cqlpjks
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:一尾狐 帖子:407 积分:3194 威望:0 精华:0 注册:2011/2/28 11:57:00
  发帖心情 Post By:2021/2/20 16:33:00 [只看该作者]

谢谢!

 回到顶部