Foxtable(狐表)用户栏目专家坐堂 → [求助]请教统计多评委数据代码简化方法


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

主题:[求助]请教统计多评委数据代码简化方法

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


加好友 发短信
等级:四尾狐 帖子:811 积分:10946 威望:0 精华:1 注册:2008/9/2 18:58:00
[求助]请教统计多评委数据代码简化方法  发帖心情 Post By: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编辑过]

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110727 积分:563555 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2023/5/8 21:19:00 [只看该作者]

Dim dt As Table = Tables("活动数据库")
For m1 As Integer = 0 To dt.rows.count - 1
dim 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

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


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

谢谢

 回到顶部