VB字符串排序(急)
来源:百度知道 编辑:UC知道 时间:2024/05/21 19:56:09
只用3个控键!!!text,picture,command
从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
...
end if
直接复制代码运行
不像排序时清除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
Dim str1() As String, NN As Integer
Private Sub Command1_Click()
NN = NN + 1
ReDim Preserve str1(NN)
str1(NN) = Text1.Text
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, str2 As String
Picture1.Cls
For i = 1 To NN - 1
For j = i + 1 To NN