以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]为什么下列代码不能实现在datacolchanged事件中实现多个表数据运算后在一个表中数据累加  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=90377)

--  作者:33chyh
--  发布时间:2016/9/11 13:24:00
--  [求助]为什么下列代码不能实现在datacolchanged事件中实现多个表数据运算后在一个表中数据累加

老师您好!
我的疑惑是在运行“卷1答”表中datacolchanged事件代码后,在“学生问题频度”表中计算出相应频度数值见图1。在运行“卷2答”表中datacolchanged事件代码后,在“学生问题频度”表中进行数值累加。图2是独立运行“卷2答”表中datacolchanged事件代码后的结果,图3应该是先运行”卷1答“再运行”卷2答“后数值累积的结果。图4是实际运行效果。请老师帮助看看是哪个地方出现问题了?
编写的代码如下:
“卷1答”代码
Dim kmdr As DataRow = DataTables("客观问题描述").find("试卷号= \'" & DataTables("卷1答").Name.chars(1) & "\'")
Dim zmdr As DataRow = DataTables("主观问题描述").find("试卷号= \'" & DataTables("卷1答").Name.chars(1) & "\'")
Dim kfdr As DataRow = DataTables("客观题答案").find("试卷号 = \'" & DataTables("卷1答").Name.chars(1) & "\'" )
Dim xswpdr As DataRow = DataTables("学生问题频度").find("学号 = \'" & e.DataRow("学号") & "\'")
For Each dr As DataRow In DataTables("卷1答").DataRows
    Dim t1 As String = e.DataRow("客观题1")
    Dim d1 As String = kfdr("客观题1")
    Dim t2 As String = e.DataRow("客观题2")
    Dim d2 As String = kfdr("客观题2")
    Dim t3 As String = e.DataRow("客观题3")
    Dim d3 As String = kfdr("客观题3")
    xswpdr("知1") = 0
    xswpdr("知2") = 0
    xswpdr("知3") = 0
    xswpdr("知4") = 0
    If t1 IsNot Nothing AndAlso t2 IsNot Nothing AndAlso t3 IsNot Nothing Then
        Dim ts() As String = {t1, t2, t3}
        Dim ds() As String = {d1, d2, d3}
        For i As Integer = 0 To ts.length-1
            For Each s As String In ts(i)
                If ds(i).Contains(s) = False Then
                    Select Case kmdr("题" & i + 1 & s.ToUpper() & "范")
                        Case "知1"
                            xswpdr("知1") = xswpdr("知1") + 1
                        Case "知2"
                            xswpdr("知2") = xswpdr("知2") +  1
                        Case "知3"
                            xswpdr("知3") = xswpdr("知3") +  1
                        Case "知4"
                            xswpdr("知4") = xswpdr("知4") +  1
                    End Select
                End If
            Next
        Next
        For i As Integer = 0 To ts.length-1
            For Each s As String In ds(i)
                If ts(i).Contains(s) = False Then
                    Select Case kmdr("题" & i + 1 & s.ToUpper() & "范")
                        Case "知1"
                            xswpdr("知1") = xswpdr("知1") + 1
                        Case "知2"
                            xswpdr("知2") = xswpdr("知2") +  1
                        Case "知3"
                            xswpdr("知3") = xswpdr("知3") +  1
                        Case "知4"
                            xswpdr("知4") = xswpdr("知4") +  1
                    End Select
                End If
            Next
        Next
    End If
    For i As Integer = 1 To 7
        If e.DataRow("主观题" & i ) = "f" Then
            Select Case zmdr("题" & i & "范")
                Case "知1"
                    xswpdr("知1") = xswpdr("知1") + 1
                Case "知2"
                    xswpdr("知2") = xswpdr("知2") +  1
                Case "知3"
                    xswpdr("知3") = xswpdr("知3") +  1
                Case "知4"
                    xswpdr("知4") = xswpdr("知4") +  1
            End Select
        End If
    Next
Next


“卷2答”代码
Dim kmdr As DataRow = DataTables("客观问题描述").find("试卷号= \'" & DataTables("卷2答").Name.chars(1) & "\'")
Dim zmdr As DataRow = DataTables("主观问题描述").find("试卷号= \'" & DataTables("卷2答").Name.chars(1) & "\'")
Dim kfdr As DataRow = DataTables("客观题答案").find("试卷号 = \'" & DataTables("卷2答").Name.chars(1) & "\'" )
Dim xswpdr As DataRow = DataTables("学生问题频度").find("学号 = \'" & e.DataRow("学号") & "\'")
If xswpdr("知1") IsNot Nothing And xswpdr("知2") IsNot Nothing  And xswpdr("知3") IsNot Nothing  And xswpdr("知4") IsNot Nothing Then
    xswpdr("知1") = xswpdr("知1")
    xswpdr("知2") = xswpdr("知2")
    xswpdr("知3") = xswpdr("知3")
    xswpdr("知4") = xswpdr("知4")
End If                                                             这部分代码是要实现继承“卷1答”计算结果,但是加入后就成了图4的结果
For Each dr As DataRow In DataTables("卷2答").DataRows
    Dim t1 As String = e.DataRow("客观题1")
    Dim d1 As String = kfdr("客观题1")
    Dim t2 As String = e.DataRow("客观题2")
    Dim d2 As String = kfdr("客观题2")
    Dim t3 As String = e.DataRow("客观题3")
    Dim d3 As String = kfdr("客观题3")
    If t1 IsNot Nothing AndAlso t2 IsNot Nothing AndAlso t3 IsNot Nothing Then
        Dim ts() As String = {t1, t2, t3}
        Dim ds() As String = {d1, d2, d3}
        For i As Integer = 0 To ts.length-1
            For Each s As String In ts(i)
                If ds(i).Contains(s) = False Then
                    Select Case kmdr("题" & i + 1 & s.ToUpper() & "范")
                        Case "知1"
                            xswpdr("知1") = xswpdr("知1") + 1
                        Case "知2"
                            xswpdr("知2") = xswpdr("知2") +  1
                        Case "知3"
                            xswpdr("知3") = xswpdr("知3") +  1
                        Case "知4"
                            xswpdr("知4") = xswpdr("知4") +  1
                    End Select
                End If
            Next
        Next
        For i As Integer = 0 To ts.length-1
            For Each s As String In ds(i)
                If ts(i).Contains(s) = False Then
                    Select Case kmdr("题" & i + 1 & s.ToUpper() & "范")
                        Case "知1"
                            xswpdr("知1") = xswpdr("知1") + 1
                        Case "知2"
                            xswpdr("知2") = xswpdr("知2") +  1
                        Case "知3"
                            xswpdr("知3") = xswpdr("知3") +  1
                        Case "知4"
                            xswpdr("知4") = xswpdr("知4") +  1
                    End Select
                End If
            Next
        Next
    End If
    For i As Integer = 1 To 7
        If e.DataRow("主观题" & i ) = "f" Then
            Select Case zmdr("题" & i & "范")
                Case "知1"
                    xswpdr("知1") = xswpdr("知1") + 1
                Case "知2"
                    xswpdr("知2") = xswpdr("知2") +  1
                Case "知3"
                    xswpdr("知3") = xswpdr("知3") +  1
                Case "知4"
                    xswpdr("知4") = xswpdr("知4") +  1
            End Select
        End If
    Next
Next

 

图片


图片点击可在新窗口打开查看此主题相关图片如下:频度累积.jpg
图片点击可在新窗口打开查看

 

源文件

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:频度累积表.foxdb


[此贴子已经被作者于2016/9/12 9:37:18编辑过]

--  作者:狐狸爸爸
--  发布时间:2016/9/11 14:41:00
--  

提问的时候,最好描述一下自己是怎么统计的,别人很难根据你的代码整理出你的统计思路,即使能够整理出来,也要花大量的时间,你描述清楚了统计过程,也许别人能给你更好的答案。

 

说实话,分析你的代码,找出你的统计思路,还要发现你代码的问题,不如你给出具体统计需求,我们直接帮你写一个来的快。

[此贴子已经被作者于2016/9/11 15:09:37编辑过]

--  作者:狐狸爸爸
--  发布时间:2016/9/11 14:48:00
--  

还有,应该掌握一下调试技巧:

http://www.foxtable.com/webhelp/scr/1485.htm

 

用一两行数据来调试分析一下统计的过程,看看关键位置的结果,你熟悉整个统计流程,调试起来,比别人方便得多。


--  作者:33chyh
--  发布时间:2016/9/11 15:49:00
--  
谢谢狐狸爸爸的提醒