Foxtable(狐表)用户栏目专家坐堂 → 两段排名代码,如何合并到一起?


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

主题:两段排名代码,如何合并到一起?

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


加好友 发短信
等级:二尾狐 帖子:559 积分:6288 威望:0 精华:0 注册:2008/9/7 20:15:00
两段排名代码,如何合并到一起?  发帖心情 Post By:2021/7/19 18:55:00 [只看该作者]


Tables("学生成绩汇总表").StopRedraw
Dim bjs As List(Of String) = DataTables("学生成绩汇总表").GetValues("年级","[年级] Is Not NULL")
Dim Count As Integer
Dim ColNames() As String = {"语文","数学","英语","化学","物理","政治","历史","地理","生物","总分"} 
Dim TotalName As String 
For Each ColName As String In ColNames '
    For i As Integer = 0 To bjs.Count -1 
        Dim drs As List(Of DataRow) = DataTables("学生成绩汇总表").Select("[年级] = '" & bjs(i) & "'", ColName & " DESC")
        Count = 0
        TotalName = ColName & "年级排名"
        For n As Integer = 0 To drs.Count - 1
            Count = Count + 1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalName ) = drs(n-1)(TotalName ) 
            Else
                drs(n)(TotalName ) = Count
            End If
        Next
    Next 
Next
Tables("学生成绩汇总表").Sort = "总分 DESC"
Tables("学生成绩汇总表").ResumeRedraw
这是学生成绩的年级排名代码


Tables("学生成绩汇总表").StopRedraw
Dim bjs As List(Of String) = DataTables("学生成绩汇总表").GetValues("班级","[班级] Is Not NULL")
Dim Count As Integer
Dim ColNames() As String = {"语文","数学","英语","化学","物理","政治","历史","地理","生物","总分"} 
Dim TotalName As String 
For Each ColName As String In ColNames '
    For i As Integer = 0 To bjs.Count -1 
        Dim drs As List(Of DataRow) = DataTables("学生成绩汇总表").Select("[班级] = '" & bjs(i) & "'", ColName & " DESC")
        Count = 0
        TotalName = ColName & "班级排名"
        For n As Integer = 0 To drs.Count - 1
            Count = Count + 1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalName ) = drs(n-1)(TotalName ) 
            Else
                drs(n)(TotalName ) = Count
            End If
        Next
    Next 
Next
Tables("学生成绩汇总表").Sort = "总分 DESC"
Tables("学生成绩汇总表").ResumeRedraw
这是学生成绩的班级排名代码,这两段代码,如何合并到一起,用一个窗口按钮公式完成,谢谢老师!


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


加好友 发短信
等级:超级版主 帖子:110750 积分:563676 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/7/19 20:30:00 [只看该作者]

把下面蓝色的代码去掉,放到一个按钮里即可
……
            Else
                drs(n)(TotalName ) = Count
            End If
        Next
    Next 
Next
Tables("学生成绩汇总表").Sort = "总分 DESC"
Tables("学生成绩汇总表").ResumeRedraw
这是学生成绩的年级排名代码


Tables("学生成绩汇总表").StopRedraw
Dim bjs As List(Of String) = DataTables("学生成绩汇总表").GetValues("班级","[班级] Is Not NULL")
Dim Count As Integer
Dim ColNames() As String = {"语文","数学","英语","化学","物理","政治","历史","地理","生物","总分"} 
Dim TotalName As String 
For Each ColName As String In ColNames '
    For i As Integer = 0 To bjs.Count -1 
        Dim drs As List(Of DataRow) = DataTables("学生成绩汇总表").Select("[班级] = '" & bjs(i) & "'", ColName & " DESC")
        Count = 0
        TotalName = ColName & "班级排名"
……

重复的变量换个不同名称
[此贴子已经被作者于2021/7/19 20:31:45编辑过]

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


加好友 发短信
等级:二尾狐 帖子:559 积分:6288 威望:0 精华:0 注册:2008/9/7 20:15:00
  发帖心情 Post By:2021/7/19 21:15:00 [只看该作者]

Tables("学生成绩汇总表").StopRedraw
Dim bjs As List(Of String) = DataTables("学生成绩汇总表").GetValues("年级","[年级] Is Not NULL")
Dim Count As Integer
Dim ColNames() As String = {"语文","数学","英语","化学","物理","政治","历史","地理","生物","总分"} 
Dim TotalName As String 
For Each ColName As String In ColNames '
    For i As Integer = 0 To bjs.Count -1 
        Dim drs As List(Of DataRow) = DataTables("学生成绩汇总表").Select("[年级] = '" & bjs(i) & "'", ColName & " DESC")
        Count = 0
        TotalName = ColName & "年级排名"
        For n As Integer = 0 To drs.Count - 1
            Count = Count + 1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalName ) = drs(n-1)(TotalName ) 
            Else
                drs(n)(TotalName ) = Count
            End If
        Next
    Next 
Next


Dim bjsP As List(Of String) = DataTables("学生成绩汇总表").GetValues("班级","[班级] Is Not NULL")
Dim CountP As Integer

Dim TotalNameP As String 
For Each ColName As String In ColNames '
    For i As Integer = 0 To bjsP.Count -1 
        Dim drs As List(Of DataRow) = DataTables("学生成绩汇总表").Select("[班级] = '" & bjsP(i) & "'", ColName & " DESC")
        Count = 0
        TotalNameP = ColName & "班级排名"
        For n As Integer = 0 To drs.Count - 1
            Count = Count + 1
            If n > 0 AndAlso drs(n)(ColName ) = drs(n-1)(ColName) Then
                drs(n)(TotalNameP ) = drs(n-1)(TotalNameP ) 
            Else
                drs(n)(TotalNameP ) = Count
            End If
        Next
    Next 
Next
谢谢老师,改好了!
[此贴子已经被作者于2021/7/19 21:24:21编辑过]

 回到顶部