vb中如何从一个文本框中提取需要的字符

例如text1.text=123456
我想将123456截成3段,分别是12、34、56,再将他们分别显示在text2、text3、text4三个文本框中,请问该怎么写代码????
Text2= Mid(Text1.Text, 0, 2)
Text3= Mid(Text1.Text, 2, 2)
Text4= Mid(Text1.Text, 4, 2)
Text5 Mid(Text1.Text, 6, 2)
我这样写了个代码,怎么说“无效调用或者参数”我又做错了什么,救命啊!!!

参考代码如下:
Private Sub Command1_Click()
Dim str5 As String
str5 = GetaLine(Text1, 1) '取得第二行的字串,以0为基底
End Sub

'以下在.Bas
Option Explicit
Const EM_GETLINE = &HC4
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String
Dim str5(255) As Byte '如果您的字串 > 255 byte请自行增加该Byte Array
Dim str6 As String, i As Long

str5(0) = 255 '字串的前两个Byte存该字串的最大长度
str5(0) = 255
i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str5(0))
If i = 0 Then
GetaLine = ""
Else
str6 = StrConv(str5, vbUnicode)
GetaLine = Left(str6, InStr(1, str6, Chr(0)) - 1)
End If
End Function
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-28
Text2.Text = Mid(Text1.Text, 1, 2)
Text3.Text = Mid(Text1.Text, 3, 2)
Text4.Text = Mid(Text1.Text, 5, 2)

正确,“无效调用或者参数”就是因为mid不能从0必须从第一位开始取值本回答被提问者采纳
第2个回答  2007-12-27
text2.text = mid(text1.text,0,2)
text3.text = mid(text1.text,2,2)
text4.text = mid(text1.text,4,2)

哦 抱歉 一时记错 mid的索引是从1开始的

text2.text = mid(text1.text,1,2)
text3.text = mid(text1.text,3,2)
text4.text = mid(text1.text,5,2)
第3个回答  2007-12-27
text2 = left(text1,2)
text3 = mid(text1,2,2)
text4 = right(text1,2)
也可,“.Text”可以省略的,不信你可以试试。
第4个回答  2007-12-27
Text2.Text = Mid(Text1.Text, 1, 2)
Text3.Text = Mid(Text1.Text, 3, 2)
Text4.Text = Mid(Text1.Text, 5, 2)
应该这样
相似回答