Foxtable(狐表)用户栏目专家坐堂 → [求助]循环次数太多,怎么处理?


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

主题:[求助]循环次数太多,怎么处理?

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


加好友 发短信
等级:一尾狐 帖子:407 积分:3194 威望:0 精华:0 注册:2011/2/28 11:57:00
[求助]循环次数太多,怎么处理?  发帖心情 Post By:2019/4/3 11:38:00 [只看该作者]

 If e.Form.Controls("年级").value Is Nothing Then
       MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
 Else

如果图片点击可在新窗口打开查看图片点击可在新窗口打开查看没有选择或输入统计年级,则出现提示框十几次,再中止。能否只出现1次提示框?请指教!谢谢!
    For Each danwei As String In danwei_list
        For Each bubie As String In DataTables("成绩库").GetValues("部别", "")
            If e.Form.Controls("年级").value Is Nothing Then
                MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
            Else
                Functions.Execute("筛选记录",dt)
                Dim nianji As String = e.Form.Controls("年级").text
                For Each ban As String In DataTables("成绩库").GetValues("班","[单位]= '" & danwei & "'And [年级]= '" & nianji & "'And [部别]= '" & bubie  & "'")
                    zdr = DataTables(  Km & "分数段" ).datarows.addnew()
                    zdr("单位") = danwei
                    zdr("部别") = bubie
                    zdr("年级") = nianji
                    zdr("班") = ban
                Next
            End If
        Next
    Next
[此贴子已经被作者于2019/4/3 11:46:06编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/4/3 11:41:00 [只看该作者]


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


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

谢谢!
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:高中期末成绩统计程序(分ab级).rar

密码:888
[此贴子已经被作者于2019/4/3 12:09:48编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/4/3 12:17:00 [只看该作者]

If e.Form.Controls("年级").value Is Nothing Then
    MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Else
    If e.Form.Controls("年级").value Is Nothing Then
        MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    Else

       
        '如果图片点击可在新窗口打开查看图片点击可在新窗口打开查看没有选择或输入统计年级,则出现提示框十几次,再中止.能否只出现1次提示框?请指教!谢谢!
        For Each danwei As String In danwei_list
            For Each bubie As String In DataTables("成绩库").GetValues("部别", "")
                Functions.Execute("筛选记录",dt)
                Dim nianji As String = e.Form.Controls("年级").text
                For Each ban As String In DataTables("成绩库").GetValues("班","[单位]= '" & danwei & "'And [年级]= '" & nianji & "'And [部别]= '" & bubie  & "'")
                    zdr = DataTables(  Km & "分数段" ).datarows.addnew()
                    zdr("单位") = danwei
                    zdr("部别") = bubie
                    zdr("年级") = nianji
                    zdr("班") = ban
                Next
               
            Next
        Next
    End If
End If

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


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

没变化?
If e.Form.Controls("年级").value Is Nothing Then
    MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Else
If e.Form.Controls("年级").value Is Nothing Then
    MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
Else
[此贴子已经被作者于2019/4/3 12:27:28编辑过]

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


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By:2019/4/3 12:32:00 [只看该作者]

If e.Form.Controls("年级").value Is Nothing Then
    'MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
    MessageBox.Show("请选择或输入统计年级后再执行此操作","中止操作",MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    Return
End If
Dim dt As Table = Tables("成绩库")
Dim s1() As String = New String() {"总分"}
Dim Kms() As String = {"总分"}
Dim fenshu_min As Integer = 300
Dim fenshu_max As Integer = 600
Dim danwei_list() As String = {"梁平中学","红旗中学","第一中学","实验中学","屏锦中学","袁驿中学","福禄中学"}
Dim liem1s() As String = {"单位","部别"}
Dim liem2s() As String = {"年级","班","参考人数","平均分","最高分"}
StatusBar.Message1= "正在生成统计数据"
Dim Time,Time1 As Date
Time = Date.now
e.Form.Controls("Label1").Text = "正在进行总分统计,请稍后……"
e.Form.Controls("Label4").Text = "正在计时…"
'Functions.Execute("筛选记录",dt)
For Each Km As String In Kms
    Dim dtb As New DataTableBuilder(Km & "分数段")
    For Each liem1 As String In liem1s
        dtb.AddDef(""& liem1 &"",Gettype(String),8)
    Next
    For Each liem2 As String In liem2s
        dtb.AddDef(""& liem2 &"",Gettype(Double))
    Next
    For i As Integer = 0 To 15
        dtb.AddDef("分数段" & (i+1) , Gettype(Double),"","" & (fenshu_max - i * 20)  & "分及以上")
    Next
    dtb.AddDef("分数段17",Gettype(Double),"","300分以下")
    dtb.Build()
    Dim tj As Double
    Dim zdr As DataRow
    For Each danwei As String In danwei_list
        For Each bubie As String In DataTables("成绩库").GetValues("部别", "")
            Functions.Execute("筛选记录",dt)
            Dim nianji As String = e.Form.Controls("年级").text
            For Each ban As String In DataTables("成绩库").GetValues("班","[单位]= '" & danwei & "'And [年级]= '" & nianji & "'And [部别]= '" & bubie & "'")
                zdr = DataTables(  Km & "分数段" ).datarows.addnew()
                zdr("单位") = danwei
                zdr("部别") = bubie
                zdr("年级") = nianji
                zdr("班") = ban
            Next
        Next
    Next
Next
For Each bm As DataTable In DataTables
    For Each dr As DataRow In DataTables(bm.name).DataRows
        If bm.name <> "成绩库" AndAlso bm.Name <> "校名设置"AndAlso bm.Name <> "目标设置" AndAlso bm.Name <> "名册"AndAlso bm.Name <> "信息表" AndAlso bm.Name <> "原始名册" AndAlso bm.Name <> "调用人数" AndAlso bm.Name <> "基数"
            DataTables(bm.name).DeleteFor("[参考人数] = 0")
            Dim tj1 As String = Left(bm.name,2)
            dr("参考人数") = DataTables("成绩库").Compute("count(单位)", "[单位] = '" & dr("单位") & "'and [班] = '" & dr("班") & "'and [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
            dr("平均分") = DataTables("成绩库").Compute("Avg(" & tj1 & ")", "[单位] = '" & dr("单位") & "'and [班] = '" & dr("班") & "'and [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
            dr("最高分") = DataTables("成绩库").Compute("Max(" & tj1 & ")",  "[单位] = '" & dr("单位") & "'and [班] = '" & dr("班") & "'and [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
            For i As Integer = 0 To 15
                dr("分数段" & (i+1)) = DataTables("成绩库").Compute("count(单位)","[单位] = '" & dr("单位") & "' and  " & tj1 & " >= '" & (fenshu_max - i * 20) & "'and [班] = '" & dr("班") & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
            Next
            dr("分数段17") = DataTables("成绩库").Compute("count(单位)","[单位] = '" & dr("单位") & "' and  " & tj1 & " < '" & fenshu_min & "'and [班] = '" & dr("班") & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
        End If
    Next
Next
For Each bm As DataTable In DataTables
    If bm.name <> "成绩库" AndAlso bm.Name <> "校名设置" AndAlso bm.Name <> "目标设置" AndAlso bm.Name <> "名册" AndAlso bm.Name <> "信息表" AndAlso bm.Name <> "原始名册" AndAlso bm.Name <> "调用人数" AndAlso bm.Name <> "基数"
        Dim dr As DataRow
        For Each bubie As String In DataTables("成绩库").GetValues("部别", "")
            If e.Form.Controls("年级").value Is Nothing Then
                MessageBox.Show("请选择期数后再执行此操作","中止操作",MessageBoxButtons.OK,MessageBoxIcon.Exclamation)
            Else
                Dim nianji As String = e.Form.Controls("年级").text
                dr = DataTables(bm.name).addnew()
                dr("单位") = "全县合计"
                dr("部别") = bubie
                dr("年级") = nianji
                Dim tj1 As String = Left(bm.name,2)
                dr("参考人数") = DataTables("成绩库").Compute("count(单位)", "[部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                dr("平均分") = DataTables("成绩库").Compute("Avg(" & tj1 & ")", "[部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                dr("最高分") = DataTables("成绩库").Compute("Max(" & tj1 & ")", "[部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                For i As Integer = 0 To 15
                    dr("分数段" & (i+1)) = DataTables("成绩库").Compute("count(单位)", "" & tj1 & " >= '" & (fenshu_max - i * 20) & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                Next
                dr("分数段17") = DataTables("成绩库").Compute("count(单位)", "" & tj1 & " < '" & fenshu_min & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                For Each danwei As String In danwei_list
                    dr = DataTables(bm.name).addnew()
                    dr("单位") = danwei
                    dr("部别") = bubie
                    dr("年级") = nianji
                    tj1 = Left(bm.name,2)
                    dr("参考人数") = DataTables("成绩库").Compute("count(单位)", "[单位] = '" & dr("单位") & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                    dr("平均分") = DataTables("成绩库").Compute("Avg(" & tj1 & ")", "[单位] = '" & dr("单位") & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                    dr("最高分") = DataTables("成绩库").Compute("Max(" & tj1 & ")",  "[单位] = '" & dr("单位") & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                    For i As Integer = 0 To 15
                        dr("分数段" & (i+1)) = DataTables("成绩库").Compute("count(单位)", "[单位] = '" & dr("单位") & "' and  " & tj1 & " >= '" & (fenshu_max - i * 20) & "'And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                    Next
                    dr("分数段17") = DataTables("成绩库").Compute("count(单位)", "[单位] = '" & dr("单位") & "'and  " & tj1 & " < '" & fenshu_min & "' And [部别] = '" & dr("部别") & "'and [年级] = '" & dr("年级") & "'")
                Next
            End If
        Next
       
    End If
Next
For Each Km As String In Kms
    Tables( Km & "分数段").SetHeaderRowHeight(50) '标题行的高度分别设为30和40
    Tables( Km & "分数段").DefaultRowHeight = 24 '将所建的默认行高设为24个像素
    Tables( Km & "分数段").SetColVisibleWidth("单位|60|部别|45|年级|45|班|26|参考人数|35|平均分|45|最高分|40|分数段1|45|分数段2|45|分数段3|45|分数段4|45|分数段5|45|分数段6|45|分数段7|45|分数段8|45|分数段9|45|分数段10|45|分数段11|45|分数段12|45|分数段13|45|分数段14|45|分数段15|45|分数段16|45|分数段17|45")
    For Each liem1 As String In liem1s
        Tables( Km & "分数段").Cols(""& liem1 &"").TextAlign = TextAlignEnum.Center
        Tables( Km & "分数段").Cols("年级").TextAlign = TextAlignEnum.Center
        DataTables( Km & "分数段").DeleteFor("[平均分] Is Null")
        For Each dr As  DataRow In DataTables( Km & "分数段").DataRows
            If dr.IsNull("平均分") = False Then
                dr("平均分")  = Math.Round(dr("平均分"),2)'确定小数位数
            End If
        Next
    Next
Next
Functions.Execute("分数段统计清零",s1,"")
StatusBar.Refresh
StatusBar.Reset
StatusBar.DefaultMessage = "统计完毕!"
e.Form.Controls("Label1").text ="统计结束,请导出数据!否则数据会丢失!"
Tables("总分分数段").Sort = "部别"
Time1 = Date.Now
e.Form.Controls("Label4").text="耗时 " & (Time1-Time).TotalSeconds & " 秒"
Functions.Execute("合计变红加粗",s1,"")
DataTables("成绩库").ResumeRedraw

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


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

谢谢!增加Return语句终止代码的执行。并要将Functions.Execute("筛选记录",dt)移至原来位置。

 回到顶部