学校考试要自动随机安排考场座位通常会提出两个要求:
1、同一年级统一随机排考场、座位;
2、同一考场相邻座位不能为同一班级学生。
随机排考场、座位比较容易,相邻座位不同班不容易。现提出解决思路:
1、按年级排序,每个年级产生一个随机数码,对这个数码按年级重新排序。
这样每个年级的所有班级、学生就随机排列了,但是免不了会出现相邻座位的学生为同班。
2、所以必须判断并找出同班相邻座位的学生,再次重排。
3、反复(1、2步骤)直至没有同班相邻。
在易表中如何实现?(表中有:年级、班级、座位等列)
1、增加(临时辅助)一字符列k,用于产生“随机数”;
2、增加(临时辅助)一逻辑列p,用于判断“相邻同班”。
下面通过按钮公式来实现以上要求。
首先:
SortCol("年级",1)-------------------按年级排序
AddCol(Grid,"k",0, False )----------增加一字符列k
AddCol(Grid,"p",3, False )----------增加一逻辑列p
第一步(对01年级):
EvalFor(Grid,"p","-1","年级","=","01")------对p列01年级的行赋值-1
1、EvalFor(Grid,"k","Rand(1)","p","=",-1)------对k列p等于-1的行赋予0-1的随机数
2、EvalFor(Grid,"k","10","年级","<>","01")-----对k列不等于01年级的行赋值10
这样对k列重新排序时就只针对01年级进行。
3、SortCol("k",1)------------------------------对k列01年级部分重新排序
4、EvalFor(Grid,"p","Cell(Row,""班级"")=Cell(Row-1,""班级"")","年级","=","01")----判断01年级同班相邻p就为-1
第二步
使用Loop()函数循环执行第一步中的1、2、3、4、直到01年级相邻不同班为止。
Loop("MinFor(Grid,""p"")=-1", "1 And 2 And 3 And 4",100)------循环条件为p列存在-1;最多循环100次
第三步
得到(01年级):
EvalFor(Grid,"p","-1","年级","=","01") And
Loop("MinFor(Grid,""p"")=-1", "EvalFor(Grid,""k"",""Rand(1)"",""p"",""="",-1) And EvalFor(Grid,""k"",""10"",""年级"",""<>"",""01"") And SortCol(""k"",1) And EvalFor(Grid,""p"",""Cell(Row,""""班级"""")=Cell(Row-1,""""班级"""")"",""年级"",""="",""01"")",100)
第四步
为了得到自动的动态对多个年级进行以上的循环判断,就需要使用一番三Eval()函数了。
Eval("EvalFor(Grid,""p"",""-1"",""年级"",""="","""+Substitute(Substitute(Substitute(Eval("Substitute(""|@|#|"",""|"","""+Substitute(ListFor(Grid,"年级",1),"|",""")+""|""+Substitute(""|@|#|"",""|"",""")+""")"),"@",""") And Loop(""MinFor(Grid,""""p"""")=-1"", ""EvalFor(Grid,""""k"""",""""Rand(1)"""",""""p"""",""""="""",-1) And EvalFor(Grid,""""k"""",""""10"""",""""年级"""",""""<>"""","""""),"#",""""") And SortCol(""""k"""",1) And EvalFor(Grid,""""p"""",""""Cell(Row,""""""""班级"""""""")=Cell(Row-1,""""""""班级"""""""")"""",""""年级"""",""""="""","""""),"|",""""")"",100) And EvalFor(Grid,""p"",""-1"",""年级"",""="",""")+""""")"",100)") And SortCol("年级",1)
到此所有年级都已经按年级排好座位(相邻不同班)
第五步
接下来就是如何按年级、班级的人数分配考场。(再利用k列)
EvalFor(Grid,"k","Concat([年级],[班级],""班教室\"",Text(CountFor(Grid,""年级"",""="",[年级],""班级"",""="",[班级])))")-----
计算出年级、班级、人数(如:01年级01班教室\55)
1、分配01年级01班级55人教室为一个考场;
EvalFor(Grid,"考室","")----------------------清空考室列
EvalFor(Grid,"考室","""01年级01班教室""",1,55)-------将"01年级01班教室"写入考室列1-55行
再SortCol(""考室"",1)-------------------------------考室列排序,把"01年级02班教室"放置最上面
EvalFor(Grid,"考室","""01年级02班教室""",1,58)-------将"01年级02班教室"写入考室列1-58行
再SortCol(""考室"",1)-------------------------------考室列排序,把"01年级03班教室"放置最上面
--------
第六步
为了得到自动的动态对多个年级多个班级进行按年级、班级的人数分配考场,就需要使用一番二Eval()函数了。
得到:
Eval("EvalFor(Grid,""考室"","""""""+Substitute(Substitute(ListFor(Grid,"k",1),"\",""""""",1,"),"|",") And SortCol(""考室"",1) And EvalFor(Grid,""考室"",""""""")+") And SortCol(""考室"",1)")
第七步
SortCol("年级",1)---------------按年级排序
EvalFor(Grid,"考室号","Left(GetPY([考室]),4)+Right(""000""+Text(CountFor(Grid,""考室"",""="",[考室],1,Row)),3)")------
----按年级、班级写入考室号
EvalFor(Grid,"准考证号","Concat(Left(GetPY([考室]),4),""KC"",Format(Row,""0000""))")------写入准考证号
DeleteCol(GridName,"p")------删除临时列
DeleteCol(GridName,"k")------删除临时列
最后按钮公式:
SortCol("年级",1) And
AddCol(Grid,"k",0, False ) And
AddCol(Grid,"p",3, False ) And
Eval("EvalFor(Grid,""p"",""-1"",""年级"",""="","""+Substitute(Substitute(Substitute(Eval("Substitute(""|@|#|"",""|"","""+Substitute(ListFor(Grid,"年级",1),"|",""")+""|""+Substitute(""|@|#|"",""|"",""")+""")"),"@",""") And Loop(""MinFor(Grid,""""p"""")=-1"", ""EvalFor(Grid,""""k"""",""""Rand(1)"""",""""p"""",""""="""",-1) And EvalFor(Grid,""""k"""",""""10"""",""""年级"""",""""<>"""","""""),"#",""""") And SortCol(""""k"""",1) And EvalFor(Grid,""""p"""",""""Cell(Row,""""""""班级"""""""")=Cell(Row-1,""""""""班级"""""""")"""",""""年级"""",""""="""","""""),"|",""""")"",100) And EvalFor(Grid,""p"",""-1"",""年级"",""="",""")+""""")"",100)") And SortCol("年级",1) And
EvalFor(Grid,"考室","") And
EvalFor(Grid,"k","Concat([年级],[班级],""班教室\"",Text(CountFor(Grid,""年级"",""="",[年级],""班级"",""="",[班级])))") And
Eval("EvalFor(Grid,""考室"","""""""+Substitute(Substitute(ListFor(Grid,"k",1),"\",""""""",1,"),"|",") And SortCol(""考室"",1) And EvalFor(Grid,""考室"",""""""")+") And SortCol(""考室"",1)") And
SortCol("年级",1) And
EvalFor(Grid,"考室号","Left(GetPY([考室]),4)+Right(""000""+Text(CountFor(Grid,""考室"",""="",[考室],1,Row)),3)") And
EvalFor(Grid,"准考证号","Concat(Left(GetPY([考室]),4),""KC"",Format(Row,""0000""))") And
DeleteCol(GridName,"p") And
DeleteCol(GridName,"k")