以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 自动分组问题 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=113200) |
||||
-- 作者:xl -- 发布时间:2018/1/11 8:38:00 -- 自动分组问题 求助:自动分组问题 说明:如何根据《分组计划》的分组数对《原始数据》中的分组列进行分组。如“地二”在“课程一”中有174人计划对原始数据中课程一分成3组,分别填写1、2、3即可。又如“历史学考”在“课程四”中有484人需对原始数据中相关列分成8组。
|
||||
-- 作者:有点甜 -- 发布时间:2018/1/11 9:11:00 -- Dim dt1 As DataTable = DataTables("分组计划") Dim dt2 As DataTable = DataTables("原始数据") Dim cs() = {"一", "二", "三", "四", "五", "六"} For Each r As DataRow In dt1.Select("") For Each c As String In cs If val(r("分组" & c)) > 0 Then Dim drs = dt2.Select("课程" & c & " = \'" & r("科目") & "\'") Dim rs As Integer = Math.Ceiling(drs.count/r("分组" & c)) For i As Integer = 1 To r("分组" & c) For j As Integer = rs*(i-1) To rs*i If j < drs.count Then drs(j)("分组" & c) = i End If Next Next End If Next Next |
||||
-- 作者:xl -- 发布时间:2018/1/11 9:42:00 -- 甜版真是神人,18行代码就搞定了 |
||||
-- 作者:xl -- 发布时间:2018/1/12 8:28:00 -- 若将科目分组编通号,2楼代码如何修改? 如“地二”分组一二三都是3个组,现将分组一编为“1,2,3”,分组二继续编为“4,5,6”,分组三编为“7,8,9”;又如:化学学考“分组四五六分别有2、6、5个组,现将分组四编为”1,2“,分组五编为”3,4,5,6,7,8“,分组六编为”9,10,11,12,13“。即将《分组计划》表中科目对应的所有分组编通号。
|
||||
-- 作者:有点甜 -- 发布时间:2018/1/12 8:46:00 -- Dim dt1 As DataTable = DataTables("分组计划") Dim dt2 As DataTable = DataTables("原始数据") Dim cs() = {"一", "二", "三", "四", "五", "六"} For Each r As DataRow In dt1.Select("") Dim idx As Integer = 0 For Each c As String In cs If val(r("分组" & c)) > 0 Then Dim drs = dt2.Select("课程" & c & " = \'" & r("科目") & "\'") Dim rs As Integer = Math.Ceiling(drs.count/r("分组" & c)) For i As Integer = 1 To r("分组" & c) idx += 1 For j As Integer = rs*(i-1) To rs*i If j < drs.count Then drs(j)("分组" & c) = idx End If Next Next End If Next Next |
||||
-- 作者:xl -- 发布时间:2018/1/12 9:07:00 -- 谢谢甜版 |