以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]取值为空,怎么还有统计值?  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=84871)

--  作者:cqlpjks
--  发布时间:2016/5/12 11:48:00
--  [求助]取值为空,怎么还有统计值?

例:

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:高三分析统计程序测试.rar

取值表:
图片点击可在新窗口打开查看此主题相关图片如下:目标设置.png
图片点击可在新窗口打开查看
统计表:
图片点击可在新窗口打开查看此主题相关图片如下:统计结果.png
图片点击可在新窗口打开查看

c10、c12、c14、c16在“目标设置”中取值为空(有红色\'空\'的单元格),怎么统计出来的 dr("目标4") 、dr("目标8") 、dr("目标12") 、dr("目标16") (红色单元格)?请指教。谢谢!


--  作者:大红袍
--  发布时间:2016/5/12 12:05:00
--  

加上判断

 

        If c10 <> Nothing Then dr("目标4") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c10 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")


--  作者:cqlpjks
--  发布时间:2016/5/12 15:26:00
--  

谢谢!

If c10 <> Nothing Then
    dr("目标4") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c10 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
If c11 <> Nothing Then
    dr("目标6") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c11 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
If c12 <> Nothing Then
    dr("目标8") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= \'" & c12 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
If c13 <> Nothing Then
    dr("目标10") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c13 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
If c14 <> Nothing Then
    dr("目标12") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c14 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
If c15 <> Nothing Then
    dr("目标14") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c15 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
If c16 <> Nothing Then
    dr("目标16") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= \'" & c16 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
End If
不能简化吗?


--  作者:大红袍
--  发布时间:2016/5/12 15:50:00
--  

Dim ary1() As String = {"目标4", "目标6"}
Dim ary2() As Double = {c10, c11}
For i As Integer = 0 To ary1.length-1
    If ary2(i) <> Nothing Then
        dr(ary(i)) = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & ary2(i) & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
    End If
Next


--  作者:cqlpjks
--  发布时间:2016/5/12 17:13:00
--  

谢谢!


--  作者:cqlpjks
--  发布时间:2016/5/13 10:15:00
--  

代码简化出错:

将原代码:
        If c9 <> Nothing Then
            dr("目标2") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c9 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If       
        If c10 <> Nothing Then
            dr("目标4") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c10 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c11 <> Nothing Then
            dr("目标6") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c11 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c12 <> Nothing Then
            dr("目标8") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= \'" & c12 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c13 <> Nothing Then
            dr("目标10") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c13 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c14 <> Nothing Then
            dr("目标12") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c14 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c15 <> Nothing Then
            dr("目标14") = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & c15 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c16 <> Nothing Then
            dr("目标16") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= \'" & c16 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
简化成:

        Dim ary1() As String = {"目标2","目标4", "目标6", "目标10", "目标12", "目标14"}
        Dim ary2() As Double =  {c9, c10, c11, c13, c14, c15}
        Dim ary3() As Double = {"高理","高理", "高理", "高文", "高文", "高文"}
        For i As Integer = 0 To ary1.length-1
            If ary2(i) <> Nothing Then
                dr(ary1(i)) = DataTables("成绩库").Compute("count(单位)", " " & tj1 & " >= \'" & ary2(i) & "\' And [部别] = \'" & ary3(i) & "\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
            End If
        Next
        If c12 <> Nothing Then
            dr("目标8") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= \'" & c12 & "\' And [部别] = \'高理\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If
        If c16 <> Nothing Then
            dr("目标16") = DataTables("成绩库").Compute("count(单位)", " 语数外 >= \'" & c16 & "\' And [部别] = \'高文\' And [年级] = \'" & dr("年级") & "\' And [类别] = \'" & tjlb & "\'")
        End If

报错:“从字符串“高理”到类型“Double”的转换无效。”。不知怎么回事?请指教。谢谢!

 


--  作者:大红袍
--  发布时间:2016/5/13 10:17:00
--  

Dim ary3() As Double = {"高理","高理", "高理", "高文", "高文", "高文"}

 

改成

 

Dim ary3() As String = {"高理","高理", "高理", "高文", "高文", "高文"}


--  作者:cqlpjks
--  发布时间:2016/5/13 10:45:00
--  

喔。我把“Double”和“String”搞忘了。谢谢!

另外再请教:我想删除整列为空的列(表中红色字体列),怎么添加删除代码?请指教,谢谢!


图片点击可在新窗口打开查看此主题相关图片如下:删除为空的列.png
图片点击可在新窗口打开查看

不然导出后生成的图表太复杂。


图片点击可在新窗口打开查看此主题相关图片如下:复杂图表.png
图片点击可在新窗口打开查看

这样要清晰些


图片点击可在新窗口打开查看此主题相关图片如下:清晰图表.png
图片点击可在新窗口打开查看
[此贴子已经被作者于2016/5/13 10:50:50编辑过]

--  作者:大红袍
--  发布时间:2016/5/13 11:00:00
--  
For i As Integer = Tables(bm).cols.count-1 To 0 Step -1
    If Tables(bm).FindRow(Tables(bm).cols(i).name & " is not null") = -1 Then
        Tables(bm).DataTable.DataCols.Delete(Tables(bm).cols(i).name)
    End If
Next

--  作者:cqlpjks
--  发布时间:2016/5/13 11:33:00
--  
谢谢!