【VB】分别将字符串a和字符串b中的字符倒置.....问题,急求大神帮忙
Private Sub Command1_Click()
On Error Resume Next
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim str1 As String
Dim str2 As String
Dim l As Integer
Dim k As Integer
Dim arr() As String
Dim brr() As String
a = "abcdefgh"
b = "1990"
c = StrReverse(a)
d = StrReverse(b)
ReDim arr(Len(a) - 1)
ReDim brr(Len(b) - 1)
For i = 1 To Len(a)
arr(i - 1) = Mid$(c, i, 1)
Next
For i = 1 To Len(b)
brr(i - 1) = Mid$(d, i, 1)
Next
k = Abs(Len(a) - Len(b))
If Len(c) - Len(d) >= 0 Then
l = Len(d)
str2 = Right(c, k)
Else
l = Len(c)
str2 = Right(d, k)
End If
For i = 1 To l
str1 = str1 + arr(i - 1) & brr(i - 1)
Next i
MsgBox str1 & str2
End Sub
在窗体上按照我上面的图片摆放三个按钮控件和两个文本框控件(名字也要一样),输入以下代码:
Private Sub Command1_Click()
On Error Resume Next
Dim a As String
Dim b As String
Dim c As String
Dim d As String
Dim str1 As String
Dim str2 As String
Dim l As Integer
Dim k As Integer
Dim arr() As String
Dim brr() As String
a = Text1
b = Text2
c = StrReverse(a)
d = StrReverse(b)
ReDim arr(Len(a) - 1)
ReDim brr(Len(b) - 1)
For i = 1 To Len(a)
arr(i - 1) = Mid$(c, i, 1)
Next
For i = 1 To Len(b)
brr(i - 1) = Mid$(d, i, 1)
Next
k = Abs(Len(a) - Len(b))
If Len(c) - Len(d) >= 0 Then
l = Len(d)
str2 = Right(c, k)
Else
l = Len(c)
str2 = Right(d, k)
End If
For i = 1 To l
str1 = str1 + arr(i - 1) & brr(i - 1)
Next i
MsgBox str1 & str2
End Sub
Private Sub Command2_Click()
Text1.Text = InputBox("请输入a")
End Sub
Private Sub Command3_Click()
Text2.Text = InputBox("请输入b")
End Sub
Private Sub Form_Load()
Command1.Caption = "交叉排序"
Command2.Caption = "输入a"
Command3.Caption = "输入b"
Text1 = ""
Text2 = ""
End Sub