VB字符串排序(很急!!!)18
发布网友
发布时间:2023-09-25 12:33
我来回答
共2个回答
热心网友
时间:2024-12-14 13:33
直接复制代码运行
如果不想排序的时候清除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
热心网友
时间:2024-12-14 13:34
Option
Explicit
Private
Sub
Command1_Click()
'排序
Dim
i%,
j%,
S()
As
String,
t
As
String
ReDim
S(Len(Trim(Text1)))
For
i
=
LBound(S)
To
UBound(S)
S(i)
=
Mid(Trim(Text1),
i
+
1,
1)
Next
For
i
=
0
To
UBound(S)
For
j
=
i
+
1
To
UBound(S)
If
S(j)
<
S(i)
Then
t
=
S(i):
S(i)
=
S(j):
S(j)
=
t
Next
Text2
=
Text2
&
S(i)
Text2
=
Trim(Text2)
Next
End
Sub
Private
Sub
Command2_Click()
'读入
Dim
Txt
As
String
Open
App.Path
&
"\test12.txt"
For
Input
As
#11
Do
While
Not
EOF(11)
Line
Input
#11,
Txt
Text1
=
Text1
&
Txt
Loop
Close
#11
End
Sub
Private
Sub
Command3_Click()
'追加
Open
App.Path
&
"\test12.txt"
For
Append
As
#12
Print
#12,
Text2
Close
#12
End
Sub