VB编程求代码。将字符串转换为ASC2码值进行从大到小排序。输入字符串和排序完后的输出在一个文本。
'水平有限只能写成这个样子了,我自己试了一下是可以的,有附图
Private Sub Command1_Click()
Dim Str1, Str2 As String
Dim i, t, j As Integer
Str1 = Text1.Text
t = Len(Str1)
Dim a() As String
ReDim a(0 To Len(Str1) - 1) '重定义数组
'******取出字符串后存入数组********
For i = 0 To Len(Str1)
If Str1 = "" Then
Exit For
End If
a(i) = Left(Str1, 1)
Str1 = Right(Str1, Len(Str1) - 1)
Next i
'************************************
'******比较数组大小******************
For i = 0 To t - 1
For j = i To t - 1
If Asc(a(i)) >= Asc(a(j)) Then
Letter = a(j)
a(j) = a(i)
a(i) = Letter
End If
Next j
Next i
'************************************
'******输出到文本框中****************
For i = 0 To t - 1
Str2 = Str2 & a(i)
Next i
Text2.Text = Str2
End Sub
Private Sub Form_Load()
'Text1.MultiLine = True'我的版本不行,说是只读属性,可在右边属性栏里更改
'Text1.ScrollBars = 2'我的版本不行,说是只读属性,可在右边属性栏里更改
Text1.Text = "" '初始化输入框
Text2.Text = "" '初始化输出框
Text2.Locked = True '第二个不能编辑便于显示
Text2.Text = "ss"
Command1.Caption = "转换"
End Sub