|
网上看到的,代码如下,比自己常用的慢5-10倍,效率还是不错的。二维数组排序没测试应该也差不多是这水平,自己的一二维数组排序是同样思路实现的,都是先得到排序后的index再调整数组。用ADO操作主要是简单通用,还能进行筛选等SQL操作。
- '* ************************************** *
- '* 模块名称:modSort.bas
- '* 模块功能:使用ADO实现数组排序
- '* 作者:http://blog.csdn.net/lyserver
- '* ************************************** *
- Sub main()
- Dim pstr As String
-
- pstr = "4aaaa/5.1hhhhhh/1.2pppppp/4.1ttttttt/5.2dddddddd"
- Dim t As Long
-
- Dim v As Variant, v_array As Variant, rs As Object
- v_array = CreateObject("EXDIY.f").GenRandomStrArray(10, 20, 100000)'生成10-20长度随机字符串10万个
- t = Timer
- CreateObject("EXDIY.f").Array1D_SortByIndex (v_array)
- Debug.Print Timer - t
-
- t = Timer
- Set rs = CreateObject("ADODB.Recordset")
- rs.Fields.Append "zd1", 129, 100
- rs.Open
- For Each v In v_array
- rs.AddNew "zd1", v
- Next
-
- rs.Sort = "zd1 ASC"
- rs.MoveFirst
- ' Do While Not rs.EOF
- ' 'Debug.Print rs.AbsolutePosition, , rs!zd1
- ' rs.MoveNext
- ' Loop
- 'arr = rs.getrows
- rs.Close
- Debug.Print Timer - t
- End Sub
复制代码
|
|