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 ,我这个是从小到大排的,你反一反就好了
温馨提示:答案为网友推荐,仅供参考