|
楼主 |
发表于 2010-5-10 21:00
|
显示全部楼层
多条件排序,先排第3列,再排第2列,可一直排下去,
Sub ruby()
Set x = CreateObject("scriptcontrol")
x.Language = "rubyscript"
y = x.eval("aa=[[1,'a',41],[4,'b',19],[2,'a',58],[7,'c',6],[3,'b',2],[6,'a',1]].sort{|x,y| x[2]<=>y[2]}.sort{|x,y| x[1]<=>y[1]}")
Stop
End Sub
也可以根据条件排序,入根据逗号里面数字排序
Sub ruby()
Set x = CreateObject("scriptcontrol")
x.Language = "rubyscript"
y = x.eval("a = ['Hitoshi,045', 'Sizuo,046', 'Yoshi,0138'].sort{|a, b| a.split(',')[1] <=> b.split(',')[1]} ")
Stop
End Sub
'字符串象数组一样处理
Sub ruby()
Set x = CreateObject("scriptcontrol")
x.Language = "rubyscript"
y = x.eval("a = 'Hitoshi,045'[2,3] ")
MsgBox y
End Sub
'数组重新整理入把里面数字相乘2x500构成新数组
Sub ruby()
Set x = CreateObject("scriptcontrol")
x.Language = "rubyscript"
y = x.eval("a = [['vine', 2, 500], ['orange', 3, 100], ['apple', 10, 50]] .map {|x| [x[0], x[1]*x[2]]} ")
Stop
End Sub
'根据重复次数排序
Sub ruby()
Set x = CreateObject("scriptcontrol")
x.Language = "rubyscript"
y = x.eval("a=[1,1,2,2,2,3].sort_by{|v| a.count(v)}.uniq")
MsgBox Join(y, ",")
End Sub
'判断范围的写法相当于 IF A>1 AND A<20
Sub ruby()
Set x = CreateObject("scriptcontrol")
x.Language = "rubyscript"
y = x.eval("(1..20) === 15 ")
MsgBox y
End Sub
[ 本帖最后由 figfig 于 2010-5-10 22:25 编辑 ] |
|