Foxtable(狐表)用户栏目专家坐堂 → [求助]怎样改动代码使其能在第二个表格中按要求运行


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

主题:[求助]怎样改动代码使其能在第二个表格中按要求运行

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


加好友 发短信
等级:幼狐 帖子:137 积分:1307 威望:0 精华:0 注册:2015/12/27 21:01:00
[求助]怎样改动代码使其能在第二个表格中按要求运行  发帖心情 Post By:2016/8/18 21:43:00 [只看该作者]

老师好!下面代码已经能在“卷1答”表中运行,在“学生问题频度”表中得出正确结果。我将这些代码放到“卷2答”表的事件datacolchanged中,运行后想将“卷2答”表中得到的结果累积到“学生问题频度”表中。请您帮助我看看这些代码应如何改动才能满足我的要求。

代码和文件如下:

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("学号") & "'")
Dim wtzj As String
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")
    wtzj = Nothing
    xswpdr("知1") = 0
    xswpdr("知2") = 0
    xswpdr("知3") = 0
    xswpdr("知4") = 0
    If t1 > "" AndAlso t2 > "" AndAlso t3 > "" 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

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目6.foxdb


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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/18 22:05:00 [只看该作者]

Dim ary() As String = {"卷1答", "卷2答"}
For Each str As String In ary
    Dim kmdr As DataRow = DataTables("客观问题描述").find("试卷号= '" & DataTables(str).Name.chars(1) & "'")
    Dim zmdr As DataRow = DataTables("主观问题描述").find("试卷号= '" & DataTables(str).Name.chars(1) & "'")
    Dim kfdr As DataRow = DataTables("客观题答案").find("试卷号 = '" & DataTables(str).Name.chars(1) & "'" )
    Dim xswpdr As DataRow = DataTables("学生问题频度").find("学号 = '" & e.DataRow("学号") & "'")
    Dim wtzj As String
    For Each dr As DataRow In DataTables(str).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")
        wtzj = Nothing
        xswpdr("知1") = 0
        xswpdr("知2") = 0
        xswpdr("知3") = 0
        xswpdr("知4") = 0
        If t1 > "" AndAlso t2 > "" AndAlso t3 > "" 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
Next

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


加好友 发短信
等级:幼狐 帖子:137 积分:1307 威望:0 精华:0 注册:2015/12/27 21:01:00
  发帖心情 Post By:2016/8/18 23:07:00 [只看该作者]

大红袍老师,谢谢您牺牲休息时间帮助我解答问题。经过将代码放到“卷2答”表的事件datacolchanged中运行后发现“学生问题频度”表中的数据不是累加的结果,与单独运行程序所得结果一样。您能再帮我看看吗?
[此贴子已经被作者于2016/8/18 23:07:48编辑过]

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


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2016/8/18 23:19:00 [只看该作者]

Dim ary() As String = {"卷1答", "卷2答"}
Dim xswpdr As DataRow = DataTables("学生问题频度").find("学号 = '" & e.DataRow("学号") & "'")
If xswpdr IsNot Nothing Then
    xswpdr("知1") = 0
    xswpdr("知2") = 0
    xswpdr("知3") = 0
    xswpdr("知4") = 0
   
    For Each str As String In ary
        Dim kmdr As DataRow = DataTables("客观问题描述").find("试卷号= '" & DataTables(str).Name.chars(1) & "'")
        Dim zmdr As DataRow = DataTables("主观问题描述").find("试卷号= '" & DataTables(str).Name.chars(1) & "'")
        Dim kfdr As DataRow = DataTables("客观题答案").find("试卷号 = '" & DataTables(str).Name.chars(1) & "'" )
        For Each dr As DataRow In DataTables(str).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 > "" AndAlso t2 > "" AndAlso t3 > "" 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
    Next
End If


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


加好友 发短信
等级:幼狐 帖子:137 积分:1307 威望:0 精华:0 注册:2015/12/27 21:01:00
  发帖心情 Post By:2016/8/19 8:30:00 [只看该作者]

大红袍老师,昨天已经很晚了您还给我提供帮助,在此表示我真挚的谢意!!!经过运行您后来提供的代码,发现与想得到的结果还有一些差距,见下图:


图片点击可在新窗口打开查看此主题相关图片如下:整合.jpg
图片点击可在新窗口打开查看
我的想法是在“卷2答”表的DataColChanged事件时应该在只运行“卷1答”表DataColChanged事件得到结果的基础上得到两者结果累计的结果。

请您再帮我看看,谢谢!

[此贴子已经被作者于2016/8/19 8:33:23编辑过]

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


加好友 发短信
等级:狐神 帖子:5015 积分:25363 威望:0 精华:0 注册:2015/8/18 9:21:00
  发帖心情 Post By:2016/8/19 10:08:00 [只看该作者]

建议“学生问题频度”增加试卷号,分别进行统计,最后进行合计。

不然每一个试卷号的答题更改都要重算其它所有试卷号的答题,没有必要

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


加好友 发短信
等级:幼狐 帖子:137 积分:1307 威望:0 精华:0 注册:2015/12/27 21:01:00
  发帖心情 Post By:2016/8/19 12:36:00 [只看该作者]

好的,谢谢老师,我试试。

 回到顶部