在文本框1中输入逗号分隔的数字序列,按下回车键,文本框2中显示排序后的数字序列。
Public Class Form1
Private Sub TextBox1_KeyPress(sender As Object, e As KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Chr(13) Then
Dim a() As String, b() As Integer
Dim i%, j%, m%, n%, t%, context$
a = Split(TextBox1.Text, ",")
n = UBound(a)
ReDim b(n)
For i = 0 To n
b(i) = Val(a(i))
Next i
For i = 0 To n - 1
For j = 0 To n - i - 1
If b(j) < b(j + 1) Then
t = b(j) : b(j) = b(j + 1) : b(j + 1) = t
End If
Next j
Next i
context = ""
For i = 0 To n
context = context & b(i) & " "
Next
TextBox2.Text = context
End If
End Sub
End Class