VB 编程 求救
要求添加2个texbox控件和一个command控件就像这样要求输入输入4个字母 然后反向输出 例如输入J K L M输出M L K J
不胜感激
追问:要求用到right left函数。。。我忘说了....
要求添加2个texbox控件和一个command控件就像这样要求输入输入4个字母 然后反向输出 例如输入J K L M输出M L K J
不胜感激
追问:要求用到right left函数。。。我忘说了....
答案:'代码如下 , 你在Text1中输入原字符串后按Command1按钮Text2中就出现与原字符串逆序的字符串:
Dim Str As StringPrivate Sub Form_Click()
Text1 = ""
Text2 = ""
End SubPrivate Sub Command1_Click()
Str = Text1
Text2 = StrReverse(Str)
End Sub
如果一定要用到right 与left函数的话可以用这种方法:
Private Sub Command1_Click()
Dim a1, a2, word, lth As String
a1 = Text1.Text
lth = Len(a1)
For i = 1 To lth
word = Right(a1, i)
a2 = a2 & Left(word, 1)
Next i
Text2.Text = a2
End Sub
经测试正确有问题欢迎追问,觉得有用的话给个好评啊~
就用倒置函数吧 StrReverse
Dim char As String
Dim x As Integer
Private Sub Text1_Change()
If x = 1 Then
char = Right(Text1.Text, 1)
Text2.Text = char & Text2.Text
End IfEnd Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then
x = 0
Text2.Text = Mid(Text2.Text, 2, Len(Text2.Text))
Else
x = 1
End If
End Sub