VB字符串排序(很急!!!)

来源:百度知道 编辑:UC知道 时间:2024/07/02 05:07:28
输入一系列字符串,按递减次序排列!!要求如图
从text里面输入,先在picture 里面 显示出来,点击“排序”按钮以后,再在 picture里面显示出来!
通用声明片段Dim n%,s(100) as string
每输入以个字符串,按ENTER,表示字符串输入结果,存放到数组中
private sub text1_KeyPress(KeyAscii as integer)
if KeyAscii =13 then
s(n)=Text
n=n+1
...

直接复制代码运行
如果不想排序的时候清除picturebox,
就把Picture1.Cls注释掉

Dim n%, s(100) As String

Private Sub Form_Load()
Command1.Caption = "排序"
End Sub

Private Sub Command1_Click()
Picture1.Cls
Dim i%, j%
For i = 1 To n - 1
For j = i + 1 To n
If s(i) < s(j) Then
t = s(i)
s(i) = s(j)
s(j) = t
End If
Next j
Next i

For i = 1 To UBound(s)
Picture1.Print s(i)
Next i
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
s(n) = Text1.text
Picture1.Print s(n)
n = n + 1
End If
End Sub