以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]如何根据条件进行加权系数的计算? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=152335) |
||||
-- 作者:hrw68529 -- 发布时间:2020/7/10 8:50:00 -- [求助]如何根据条件进行加权系数的计算? 说明:(1)在表A中,如果“是否加权”为false,则“加权系数”不进行计算; (2)如果“是否加权”为true,则“加权系数”进行计算;代码如下: Select Case e.DataCol.name Case "是否加权","面试成绩" Dim zgf1, zgf2, zdf1, zdf2 As Double Dim dt As Table = Tables("表A") For Each dr As Row In dt.Rows If dr("是否加权")=False Then dr("加权系数") = Nothing ElseIf dr("是否加权")=True Then Dim drs As List(Of Row) = Tables("表A").Select("天数=\'" & dr("天数") & "\' and 面试室=\'" & dr("面试室") & "\'And 面试成绩 Is Not Null", "面试成绩") zgf1 = drs(drs.Count-1)("面试成绩") zgf2 = drs(drs.Count-2)("面试成绩") zdf1 = drs(0)("面试成绩") zdf2 = drs(1)("面试成绩") Dim sum As Double = Tables("笔试成绩").Compute("sum(面试成绩)","天数=\'" & dr("天数") & "\' and 面试室=\'" & dr("面试室") & "\'") If e.Form.Controls("个数").text = 2 Then Dim mss As Double = (sum - zgf1 - zdf1) /( drs.Count - 2) Dim jqz As Double = dt.Compute("avg(mss)", "天数=\'" & dr("天数") & "\'") dr("加权系数") = Format(jqz/mss,"0.0000") ElseIf e.Form.Controls("个数").text = 4 Then Dim mss As Double = (sum - zgf1 - zgf2 - zdf1 - zdf2) /( drs.Count - 4) Dim jqz As Double = dt.Compute("avg(mss)", "天数=\'" & dr("天数") & "\'") dr("加权系数") = Format(jqz/mss,"0.0000") End If End If Next End Select 但就是显示错误,不知道什么地方出了问题,请专家指导。 实例如下:
[此贴子已经被作者于2020/7/10 8:50:27编辑过]
|
||||
-- 作者:有点蓝 -- 发布时间:2020/7/10 9:37:00 -- Dim zgf1, zgf2, zdf1, zdf2 As Double Dim dt As Table = Tables("表A") For Each dr As Row In dt.Rows If dr("是否加权")=False Then dr("加权系数") = Nothing Else Dim drs As List(Of dataRow) = dataTables("表A").Select("天数=\'" & dr("天数") & "\' and 面试室=\'" & dr("面试室") & "\'And 面试成绩 Is Not Null", "面试成绩") zgf1 = drs(drs.Count-1)("面试成绩") zgf2 = drs(drs.Count-2)("面试成绩") zdf1 = drs(0)("面试成绩") zdf2 = drs(1)("面试成绩") Dim sum As Double = Tables("笔试成绩").Compute("sum(面试成绩)","天数=\'" & dr("天数") & "\' and 面试室=\'" & dr("面试室") & "\'") If e.Form.Controls("个数").text = 2 Then Dim mss As Double = (sum - zgf1 - zdf1) /( drs.Count - 2) Dim jqz As Double = dt.Compute("avg(mss)", "天数=\'" & dr("天数") & "\'") dr("加权系数") = Format(jqz/mss,"0.0000") ElseIf e.Form.Controls("个数").text = 4 Then Dim mss As Double = (sum - zgf1 - zgf2 - zdf1 - zdf2) /( drs.Count - 4) Dim jqz As Double = dt.Compute("avg(mss)", "天数=\'" & dr("天数") & "\'") dr("加权系数") = Format(jqz/mss,"0.0000") End If End If Next
|
||||
-- 作者:hrw68529 -- 发布时间:2020/7/12 16:21:00 -- 不好意思,前几天出差,今天回来,加入代码后,出现对话框“未知错误”,不知什么原因?请指导,谢谢 |
||||
-- 作者:有点蓝 -- 发布时间:2020/7/12 20:35:00 -- 把项目文件复制到其它地方重新打开测试。注意项目文件所在的路径、文件名不能有括号等特殊字符 |