这里是以集合的方式进行排序,为什么会出错:要求对象? Dim Coll As New Collection
Coll.Add 1
Coll.Add 8
Coll.Add 3
Coll.Add 5
Coll.Add 7
For i = 1 To Coll.Count
For j = 1 To Coll.Count - i
If Coll(j) > Coll(j + 1) Then
Dim tmp As Integer
tmp = Coll(j)
Coll(j) = Coll(j + 1)
Coll(j + 1) = tmp
End If
Next j
Next i
For i = 0 To Coll.Count
Debug.Print Coll(i)
Next i
Coll.Add 1
Coll.Add 8
Coll.Add 3
Coll.Add 5
Coll.Add 7
For i = 1 To Coll.Count
For j = 1 To Coll.Count - i
If Coll(j) > Coll(j + 1) Then
Dim tmp As Integer
tmp = Coll(j)
Coll(j) = Coll(j + 1)
Coll(j + 1) = tmp
End If
Next j
Next i
For i = 0 To Coll.Count
Debug.Print Coll(i)
Next i
解决方案 »
- setup factory7.0的问题?
- 怎么能实现commandbutton自动的下压弹起(比如,按键盘上某个键时,相应按钮自动下压后弹起!!!)
- 用Output方式打开隐藏文件的时候出错!
- word文档中的控件,不能创建,不能退出设计模式,是什么原因呀!
- 控件adodc的使用问题
- winsock是不是不能用在多线程里?
- 如何用vb 获得其它音乐播放器正在播放的音乐的节拍
- 勇士\高手,在哪?_______如何实现mschart的x轴和Y轴一样可以用数值自动递增,显示主网格线和细网格线。
- 生成随机数
- VB和access开发系统
- 这段代码哪有语法错误啊?总是报“case 没有 select case ”的错,哪位高人指导一下啊?
- 如何获取当前打印机名称?
redim x(Coll.Count)
For i = 1 To Coll.Count
x(i)=Coll(i)
next
'下面写排序
'写回集合
set Coll=new collection
For i = 1 To ubound(x)
Coll.Add x(i)
next
Coll.Add 1
Coll.Add 8
Coll.Add 3
Coll.Add 5
Coll.Add 7
Dim i As Integer
Dim j As Integer
Dim IntMax As Integer, IntMaxIndex As Integer
For i = Coll.Count To 1 Step -1
IntMax = 0: IntMaxIndex = 1
For j = 1 To i
If Coll(j) >= IntMax Then IntMax = Coll(j): IntMaxIndex = j
Next
Coll.Remove IntMaxIndex
Coll.Add IntMax
Next i
For i = 1 To Coll.Count
Debug.Print Coll(i)
Next i输出:
8
7
5
3
1