# Re: 排序?

Posted by 小琳 on August 04, 1999 at 20:56:59:

In Reply to: 排序? posted by 阿钦 on August 03, 1999 at 22:58:01:

: 请问各位高手，我要如用VB使Richtextbox内之字串自动排序，有小至大或大至小都可以，像下面这样子可以作到吗?
: 12345
: 23456
: 54689
: 75990
: 以字串最小的往下一直排!谢谢

:::对于您的问题，小女子利用一些时间来为您解决，但是
小女子的程式只能使用整数型态的数字资料而己，小女子
首先将这些资料全部放在阵列里，然后利用阵列里的资料
来做排序，程式如下：
Option Explicit
Dim record As Integer
Private Sub Command1_Click()
Dim i As Integer
Dim temp() As Integer, j As Integer
Dim k As Integer
record = record - 1
ReDim temp(record)
j = 0
i = InStr(1, RichTextBox1.Text, Chr(10))
k = 1
Do While i <> 0
temp(j) = Mid(RichTextBox1.Text, k, i - k)
j = j + 1
k = i + 1
i = i + 1
i = InStr(i, RichTextBox1.Text, Chr(10))
Loop
For i = 0 To UBound(temp)
For j = i + 1 To UBound(temp)
If temp(i) > temp(j) Then
k = temp(i)
temp(i) = temp(j)
temp(j) = k
End If
Next j
Next i
For i = 0 To UBound(temp)
Form1.Print temp(i)
Next i
End Sub

Private Sub Form_Load()
record = 0
End Sub

Private Sub RichTextBox1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
record = record + 1
End If
End Sub

Follow Ups: