- 积分
- 5987
- 明经币
- 个
- 注册时间
- 2006-7-8
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2007-12-3 20:04:00
|
显示全部楼层
本帖最后由 作者 于 2007-12-3 21:19:50 编辑
以下的排序方法:
不重复排序+冒泡排序方法- Sub als() Dim xm, xm1
- Dim tt As AcadText, ll As AcadLine, Ent As AcadEntity
- aii = 0
- ReDim xm(60) As Long, xm1(60) As Long
- For Each Ent In ThisDrawing.ModelSpace
- Select Case Ent.ObjectName
- Case "AcDbLine"
- Set ll = Ent
- xm(aii) = ll.EndPoint(0)
- xm1(aii) = ll.EndPoint(1)
- aii = aii + 1
- End Select
- Next Ent
- ReDim Preserve xm1(1000) As Long
- bb = xx(xm1)
- Dim abc() As Long
- ReDim abc(UBound(bb)) As Long
- For ii = 0 To UBound(bb)
- abc(ii) = Val(bb(ii))
- Next ii
-
- cc = Bubble_Sort(abc)
- For ii = 0 To UBound(cc)
- Debug.Print ii, "-", cc(ii)
- Next ii
- ReDim Preserve xm(1000) As Long
- bb = xx(xm)
-
- ReDim abc(UBound(bb)) As Long
- For ii = 0 To UBound(bb)
-
- abc(ii) = Val(bb(ii))
-
- Next ii
-
- ccc = Bubble_Sort(abc)
- For ii = 0 To UBound(ccc)
- Debug.Print ii, "-", ccc(ii)
- Next ii
- ReDim xm(0), xm1(0)
- End Sub
-
- Function xx(xm)
- Dim arr() As String, Temp() As String '声明变量
- Dim s%, r% '声明单值变量
- On Error Resume Next '启动一个错误处理程序
-
- r = 0 '初值
- s = UBound(xm) '最大下标
-
- For i = 0 To s '循环
- Temp = Filter(arr, xm(i)) '搜索数组
-
- If UBound(Temp) = -1 Then '如果未找到
- ReDim Preserve arr(0 To r) '定义动态数组大小
- arr(r) = xm(i) '把姓名复制到数组Arr()中。
- r = r + 1 '序号,自增1
- End If
- Next
- xx = arr
- End Function
- Function Bubble_Sort(Ary)
- Dim aryUBound, i, j
- aryUBound = UBound(Ary)
- For ii = 0 To aryUBound
- Ary(ii) = Val(Round(Ary(ii), 2))
- Next ii
- For i = 0 To aryUBound
- For j = i + 1 To aryUBound
- If Ary(i) < Ary(j) Then
- Swap Ary(i), Ary(j)
- End If
- Next
- Next
- Bubble_Sort = Ary
- End Function
- Function Swap(a, b)
- Dim tmp
- tmp = a
- a = b
- b = tmp
- End Function
|
|