发布网友 发布时间:2022-11-03 18:42
共1个回答
热心网友 时间:2023-11-01 20:34
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
追问能不能帮我把程序改成符合图中的样式
点击【输入a】将值输入,点击b也是,最后点击【交叉排序】直接在text3中输出字符串
麻烦了
在窗体上按照我上面的图片摆放三个按钮控件和两个文本框控件(名字也要一样),输入以下代码:
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