新建一工程,在窗体上拖入一command控件,进入代码区,删除所有代码后,粘贴以下代码即可:
Option Explicit
Private Sub Command1_Click()
Dim InS As String, S As String, T As String
Dim I As Integer, J As Integer, L As String
Dim C() As String, X As String
InS = InputBox("请输入字符串", "", "1Ae4ui95487KuywY1Z2Faz")
If InS = "" Then Exit Sub
J = Len(InS)
For I = 1 To J
S = Mid(InS, I, 1)
'找出所有字母,并保存在变量T中
If (Asc(S) > 64 And Asc(S) < 91) Or (Asc(S) > 96 And Asc(S) < 123) Then
T = T & S & " "
End If
Next I
T = Trim(T)
C = Split(T, " ")
L = UBound(C)
'对字母按逆序排列
For I = 0 To L - 1
For J = I + 1 To L
If C(I) < C(J) Then X = C(I): C(I) = C(J): C(J) = X
Next J
Next I
'输出到窗体上
For I = 0 To L
Print C(I);
Next I
End Sub
输入一段字符串,1Ae4ui95487KuywY1Z2Faz,运行效果如下: