以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]循环次数太多,怎么处理?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=132977)

--  作者:cqlpjks
--  发布时间: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编辑过]

--  作者:有点甜
--  发布时间:2019/4/3 11:41:00
--  

上传具体实例测试

 

http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=78

 


--  作者:cqlpjks
--  发布时间:2019/4/3 12:02:00
--  
谢谢!
 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:高中期末成绩统计程序(分ab级).rar

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

--  作者:有点甜
--  发布时间: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
--  发布时间: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编辑过]

--  作者:有点甜
--  发布时间: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
--  发布时间:2019/4/3 12:45:00
--  
谢谢!增加Return语句终止代码的执行。并要将Functions.Execute("筛选记录",dt)移至原来位置。