VB中输入一系列字符串,将字符串按递减次序排列 编程实现

2024-11-16 10:31:05
推荐回答(1个)
回答1:

'一、在窗体中添加控件text1(Multiline=true),text2(Multiline=true)及command1
'二、复制以下代码
Option Explicit
'功能:字符串按递减次序排列
'参数:p 一系列的字符串,用回车符分开
'返回值:排序后的字符串系列
Function Sort(p As String) As String
Dim S() As String, zf As String
Dim i As Integer, j As Integer
zf = p
S = Split(zf, vbNewLine)
For i = 0 To UBound(S)
For j = 0 To UBound(S)
If j > i Then
If S(j) > S(i) Then
zf = S(i)
S(i) = S(j)
S(j) = zf
End If
End If
Next j
Next i
Sort = Join(S, vbNewLine)
End Function

Private Sub Command1_Click()
Text2.Text = Sort(Text1.Text)
End Sub

'三、在text1中输入字符串系列,用回车符分开,按下command1,即可在text2中看到结果。