求教!vb 让十多个数从大到小排列!

如果在text1中输入数据,输入一个按一下回车,如15,28,17,33,41。每输入一个,在list1中就会加入一个,并自动按从大到小排列!有这种方法吗?
这个并不麻烦,只要把list1的sorted属性设成true就行了,但我的问题是如果那几个数字中有2,和100怎么办?

1.我不知道你所讲的2和100什么意思,我不觉得它们是特殊数字
2.关于listbox的Sorted排序我知道它对字母进行排序,不知道数字是否可以?
3.我做了个程序
(1个TextBox;1个CommandBox;1个ListBox)
在下面的程序中,采用按钮和直接回车是同样效果
===========
Dim txtInput As Double
Dim A(100) As Double
Dim temp As Double
Dim n As Integer
Dim i, j As Integer

Private Sub Command1_Click()
If Text1.Text = "" Then
MsgBox "输入为空!"
Text1.SetFocus
Exit Sub
End If
If IsNumber = False Then
MsgBox "请输入数字!"
Text1.Text = ""
Text1.SetFocus
Exit Sub
End If
txtInput = Val(Text1.Text)
A(n) = txtInput
n = n + 1
SortNumbers
Text1.Text = ""
End Sub

Private Sub Form_Load()
Text1.Text = ""
n = 0
End Sub

'判断输入是否为数字
Private Function IsNumber() As Boolean
IsNumber = True
If IsNumeric(Text1.Text) = False Then
IsNumber = False
End If
End Function

Private Function SortNumbers()
If n = 1 Then
List1.AddItem A(0)
Exit Function
Else
For i = 1 To n
For j = 1 To n - i
If A(j - 1) >= A(j) Then
temp = A(j - 1)
A(j - 1) = A(j)
A(j) = temp
End If
Next j
Next i
End If
List1.Clear
For i = 0 To n - 1
List1.AddItem A(i)
Next i
End Function

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1_Click
End If
End Sub

=================
该程序我测试了下,好像OK
==========
sorry ,我这个是从小到大排的,你反一反就好了
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-04-13
没听说!