以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]请教统计多评委数据代码简化方法 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=186520) |
-- 作者:方丈 -- 发布时间:2023/5/8 19:20:00 -- [求助]请教统计多评委数据代码简化方法 以下为统计多评委评分数据的方法(28位评委,去掉3个最大值,去掉3个最小值), 请教:如何简化代码?如果评委人数比28人还多或者不固定人数,这样写代码太麻烦,谢谢! \'统计评委1到评委28的值 Dim dt As Table = Tables("活动数据库") For m1 As Integer = 0 To dt.rows.count - 1 Dim p1 As Single = dt.Rows(m1)("评委1") Dim p2 As Single = dt.Rows(m1)("评委2") Dim p3 As Single = dt.Rows(m1)("评委3") Dim p4 As Single = dt.Rows(m1)("评委4") Dim p5 As Single = dt.Rows(m1)("评委5") Dim p6 As Single = dt.Rows(m1)("评委6") Dim p7 As Single = dt.Rows(m1)("评委7") Dim p8 As Single = dt.Rows(m1)("评委8") Dim p9 As Single = dt.Rows(m1)("评委9") Dim p10 As Single = dt.Rows(m1)("评委10") Dim p11 As Single = dt.Rows(m1)("评委11") Dim p12 As Single = dt.Rows(m1)("评委12") Dim p13 As Single = dt.Rows(m1)("评委13") Dim p14 As Single = dt.Rows(m1)("评委14") Dim p15 As Single = dt.Rows(m1)("评委15") Dim p16 As Single = dt.Rows(m1)("评委16") Dim p17 As Single = dt.Rows(m1)("评委17") Dim p18 As Single = dt.Rows(m1)("评委18") Dim p19 As Single = dt.Rows(m1)("评委19") Dim p20 As Single = dt.Rows(m1)("评委20") Dim p21 As Single = dt.Rows(m1)("评委21") Dim p22 As Single = dt.Rows(m1)("评委22") Dim p23 As Single = dt.Rows(m1)("评委23") Dim p24 As Single = dt.Rows(m1)("评委24") Dim p25 As Single = dt.Rows(m1)("评委25") Dim p26 As Single = dt.Rows(m1)("评委26") Dim p27 As Single = dt.Rows(m1)("评委27") Dim p28 As Single = dt.Rows(m1)("评委28") Dim ary() As Single = {p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28} array.sort(ary) Dim zdz As Single = 0 Dim zxz As Single = 0 For i As Integer = 0 To 2 zxz += ary(i) dt.Rows(m1)("最小值之和") = zxz Next For i As Integer = ary.length - 3 To ary.length - 1 zdz += ary(i) dt.Rows(m1)("最大值之和") = zdz Next Next Next [此贴子已经被作者于2023/5/8 19:30:03编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/5/8 21:19:00 -- Dim dt As Table = Tables("活动数据库") For m1 As Integer = 0 To dt.rows.count - 1dim lst as new list(of Single ) for each c as col in dt.cols if c.name like "评委*" then lst.add(dt.Rows(m1)(c.name)) end if next lst.sort dt.Rows(m1)("最小值之和") = lst(0) + lst(1)+lst(2) dim m as integer = lst.count - 1 dt.Rows(m1)("最大值之和") = lst(m) + lst(m-1)+lst(m-2) next
|
-- 作者:方丈 -- 发布时间:2023/5/8 22:51:00 -- 谢谢 |