以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]成绩转换等级排除空值(缺考)代码  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=68474)

--  作者:方丈
--  发布时间: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编辑过]

--  作者:大红袍
--  发布时间: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


--  作者:方丈
--  发布时间:2015/5/19 22:08:00
--  

可以了,谢谢!但是:

 

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

 

Dim v As Double = i /cnt

 

 

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

 

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


--  作者:大红袍
--  发布时间: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


--  作者:方丈
--  发布时间: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编辑过]

--  作者:大红袍
--  发布时间:2015/5/20 22:01:00
--  
 上传例子。
--  作者:大红袍
--  发布时间: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

 


--  作者:方丈
--  发布时间: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


--  作者:大红袍
--  发布时间:2015/5/20 22:28:00
--  

看7楼。


--  作者:大红袍
--  发布时间: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