Foxtable(狐表)用户栏目专家坐堂 → [求助]成绩转换等级排除空值(缺考)代码


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

主题:[求助]成绩转换等级排除空值(缺考)代码

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


加好友 发短信
等级:四尾狐 帖子:811 积分:10928 威望:0 精华:1 注册:2008/9/2 18:58:00
[求助]成绩转换等级排除空值(缺考)代码  发帖心情 Post By:2015/5/18 22:58:00 [只看该作者]

以下是把“成绩”(分数)根据一定的比例转换为 “等级”  的代码,由于各科成绩可能有“空”(缺考,可能每科都不同)的,怎样把“缺考”对象(科目)的等级填入“缺考”两字,并排除在等级计算对象之外,求补充代码

 

Dim ksmc As String = e.Form.Controls("ComboBox01").text
DataTables("学生成绩库").LoadFilter = "[考试名称] = '" & ksmc & "'"
DataTables("学生成绩库").Load()

Dim vals() As Double = {0.2,0.5,0.9}
Dim nms() As String = {"政治","语文","数学","英语"}
Dim cnt As Integer = DataTables("学生成绩库").DataRows.count
For Each nm As String In nms
Dim drs As List (of DataRow) = DataTables("学生成绩库").Select("", nm & " Desc")
Dim dn As String = nm & "等级"
For i As Integer = 0 To drs.count - 1
Dim v As Double = i /cnt
If v > vals(2) Then
drs(i)(dn) = "D"
ElseIf v > vals(1) Then
drs(i)(dn) = "C"
ElseIf v > vals(0) Then
drs(i)(dn) = "B"
Else
drs(i)(dn) = "A"
End If
Next
Next

[此贴子已经被作者于2015/5/18 22:58:40编辑过]

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


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

Dim ksmc As String = e.Form.Controls("ComboBox01").text
DataTables("学生成绩库").LoadFilter = "[考试名称] = '" & ksmc & "'"
DataTables("学生成绩库").Load()

Dim vals() As Double = {0.2,0.5,0.9}
Dim nms() As String = {"政治","语文","数学","英语"}
Dim cnt As Integer = DataTables("学生成绩库").DataRows.count
For Each nm As String In nms
    Dim drs As List (of DataRow) = DataTables("学生成绩库").Select(nm & " <> 0 And " & nm & " Is not null", nm & " Desc")
    Dim dn As String = nm & "等级"
    For i As Integer = 0 To drs.count - 1
        Dim v As Double = i /cnt
        If v > vals(2) Then
            drs(i)(dn) = "D"
        ElseIf v > vals(1) Then
            drs(i)(dn) = "C"
        ElseIf v > vals(0) Then
            drs(i)(dn) = "B"
        Else
            drs(i)(dn) = "A"
        End If
    Next
    DataTables("学生成绩库").ReplaceFor("等级", "缺考", nm & " = 0 or " & nm & " Is null")
Next


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


加好友 发短信
等级:四尾狐 帖子:811 积分:10928 威望:0 精华:1 注册:2008/9/2 18:58:00
  发帖心情 Post By:2015/5/19 22:08:00 [只看该作者]

可以了,谢谢!但是:

 

Dim cnt As Integer = DataTables("学生成绩库").DataRows.count

 

Dim v As Double = i /cnt

 

 

这里的 cnt  包括了 0分和缺考对象 

 

我想把这两种(0分和缺考对象)排除掉,剩下有分数的对象再按比例分等级,怎办?谢谢!


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


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

Dim ksmc As String = e.Form.Controls("ComboBox01").text
DataTables("学生成绩库").LoadFilter = "[考试名称] = '" & ksmc & "'"
DataTables("学生成绩库").Load()

Dim vals() As Double = {0.2,0.5,0.9}
Dim nms() As String = {"政治","语文","数学","英语"}
For Each nm As String In nms
    Dim drs As List (of DataRow) = DataTables("学生成绩库").Select(nm & " <> 0 And " & nm & " Is not null", nm & " Desc")
    Dim dn As String = nm & "等级"
    Dim cnt As Integer = drs.Count
    For i As Integer = 0 To drs.count - 1
        Dim v As Double = i /cnt
        If v > vals(2) Then
            drs(i)(dn) = "D"
        ElseIf v > vals(1) Then
            drs(i)(dn) = "C"
        ElseIf v > vals(0) Then
            drs(i)(dn) = "B"
        Else
            drs(i)(dn) = "A"
        End If
    Next
    DataTables("学生成绩库").ReplaceFor("等级", "缺考", nm & " = 0 or " & nm & " Is null")
Next


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


加好友 发短信
等级:四尾狐 帖子:811 积分:10928 威望:0 精华:1 注册:2008/9/2 18:58:00
  发帖心情 Post By:2015/5/20 22:00:00 [只看该作者]

Dim vals() As Double = {0.2,0.5,0.9}

 

 For i As Integer = 0 To drs.count - 1
        Dim v As Double = i /cnt

If v > vals(2) Then
            drs(i)(dn) = "D"

 

 

如果有8个相同的分数(如 60分  ),这样排的话,有可能 5个是 "C”

,3个是"D”, 这有点不公平,同样的分数,要么都是"C”,要么都是"D”,

   请教, 有什么好的解决方法吗?

[此贴子已经被作者于2015/5/20 22:00:24编辑过]

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


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

 上传例子。

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


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

Dim ksmc As String = e.Form.Controls("ComboBox01").text
DataTables("学生成绩库").LoadFilter = "[考试名称] = '" & ksmc & "'"
DataTables("学生成绩库").Load()

Dim vals() As Double = {0.2,0.5,0.9}
Dim nms() As String = {"政治","语文","数学","英语"}
For Each nm As String In nms
    Dim drs As List (of DataRow) = DataTables("学生成绩库").Select(nm & " <> 0 And " & nm & " Is not null", nm & " Desc")
    Dim dn As String = nm & "等级"
    Dim cnt As Integer = drs.Count
    Dim pnm As Double = 0
    Dim pdn As String = ""
    For i As Integer = 0 To drs.count - 1
        If drs(i)(nm) = pnm Then
            drs(i)(dn) = pdn
        Else
            Dim v As Double = i /cnt
            If v > vals(2) Then
                drs(i)(dn) = "D"
            ElseIf v > vals(1) Then
                drs(i)(dn) = "C"
            ElseIf v > vals(0) Then
                drs(i)(dn) = "B"
            Else
                drs(i)(dn) = "A"
            End If
            pnm = drs(i)(nm)
            pdn = drs(i)(dn)
        End If
    Next
    DataTables("学生成绩库").ReplaceFor("等级", "缺考", nm & " = 0 or " & nm & " Is null")
Next

 


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


加好友 发短信
等级:四尾狐 帖子:811 积分:10928 威望:0 精华:1 注册:2008/9/2 18:58:00
  发帖心情 Post By:2015/5/20 22:25:00 [只看该作者]

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

 

如政治科:

 

13个 60分     7个A  6个B

12个 44分     4个B  8个C

12个 20分      5个C 7个D


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


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

看7楼。


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


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

 

Dim vals() As Double = {0.2,0.5,0.9}
Dim nms() As String = {"政治","语文","数学","英语"}
For Each nm As String In nms
    Dim drs As List (of DataRow) = DataTables("学生成绩库").Select(nm & " <> 0 And " & nm & " Is not null", nm & " Desc")
    Dim dn As String = nm & "等级"
    Dim cnt As Integer = drs.Count
    Dim pnm As Double = 0
    Dim pdn As String = ""
    For i As Integer = 0 To drs.count - 1
        If drs(i)(nm) = pnm Then
            drs(i)(dn) = pdn
        Else
            Dim v As Double = i /cnt
            If v > vals(2) Then
                drs(i)(dn) = "D"
            ElseIf v > vals(1) Then
                drs(i)(dn) = "C"
            ElseIf v > vals(0) Then
                drs(i)(dn) = "B"
            Else
                drs(i)(dn) = "A"
            End If
            pnm = drs(i)(nm)
            pdn = drs(i)(dn)
        End If
    Next
    DataTables("学生成绩库").ReplaceFor(nm & "等级", "缺考", nm & " = 0 or " & nm & " Is null")
Next


 回到顶部
总数 11 1 2 下一页