VB编程如何将TextBox里的内容拆分并写入指定的其它TextBox中?
如图,点击“拆分录入”按钮,即将Text1里面的内容逐句写入左边的文本框中。我是初级菜鸟,请高手给出使用的函数及代码,也方便以后有同样问题的朋友们看到,谢谢!如果有高手给...
如图,点击“拆分录入”按钮,即将Text1里面的内容逐句写入左边的文本框中。
我是初级菜鸟,请高手给出使用的函数及代码,也方便以后有同样问题的朋友们看到,谢谢!如果有高手给出解决方案并且我执行通过了,一定会给出实质性的奖励. 展开
我是初级菜鸟,请高手给出使用的函数及代码,也方便以后有同样问题的朋友们看到,谢谢!如果有高手给出解决方案并且我执行通过了,一定会给出实质性的奖励. 展开
展开全部
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Sub TB_GetLine(ByVal hWnd As Long, ByVal whichLine As Long, Line As String)
Dim length As Long
Dim bArr() As Byte
Dim bArr2() As Byte
Dim lc As Long
lc = SendMessage(hWnd, EM_LINEINDEX, whichLine, ByVal 0&)
length = SendMessage(hWnd, EM_LINELENGTH, lc, ByVal 0&)
If length > 0 Then
ReDim bArr(length + 1) As Byte, bArr2(length - 1) As Byte
Call RtlMoveMemory(bArr(0), length, 2)
Call SendMessage(hWnd, EM_GETLINE, whichLine, bArr(0))
Call RtlMoveMemory(bArr2(0), bArr(0), length)
Line = StrConv(bArr2, vbUnicode)
Else
Line = ""
End If
End Sub
如上的函数可以读出文本框中每行的值,调用方法如下,其中0为第一行
Call TB_GetLine(Text1.hWnd, 0, S)
Text2.Text = S
接下来你自己知道怎么做了吧。
Private Const EM_LINELENGTH = &HC1
Private Const EM_LINEINDEX = &HBB
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Private Sub TB_GetLine(ByVal hWnd As Long, ByVal whichLine As Long, Line As String)
Dim length As Long
Dim bArr() As Byte
Dim bArr2() As Byte
Dim lc As Long
lc = SendMessage(hWnd, EM_LINEINDEX, whichLine, ByVal 0&)
length = SendMessage(hWnd, EM_LINELENGTH, lc, ByVal 0&)
If length > 0 Then
ReDim bArr(length + 1) As Byte, bArr2(length - 1) As Byte
Call RtlMoveMemory(bArr(0), length, 2)
Call SendMessage(hWnd, EM_GETLINE, whichLine, bArr(0))
Call RtlMoveMemory(bArr2(0), bArr(0), length)
Line = StrConv(bArr2, vbUnicode)
Else
Line = ""
End If
End Sub
如上的函数可以读出文本框中每行的值,调用方法如下,其中0为第一行
Call TB_GetLine(Text1.hWnd, 0, S)
Text2.Text = S
接下来你自己知道怎么做了吧。
展开全部
Private Sub Command1_Click()
s = Split(Text1, vbCrLf) '分拆元素
For i = 0 To UBound(s) - 1 '因为最后一行是空行,所以元素个素减一
Controls("text" & i + 2).Text = s(i) 'text与元素相差2(自己都说不明白,呵呵,反正是这个意思)
Next i
End Sub
s = Split(Text1, vbCrLf) '分拆元素
For i = 0 To UBound(s) - 1 '因为最后一行是空行,所以元素个素减一
Controls("text" & i + 2).Text = s(i) 'text与元素相差2(自己都说不明白,呵呵,反正是这个意思)
Next i
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
研究了下 给个思路
搜索到回车符,然后用数组分段 做法参照下面
a=text1.text
dim b
b=split(a,vbcrlf)
可以将a分成以回车符分隔的一个数组。vbcrlf是回车符的常量。然后你就可以用b(0)来引用第一个回车符前的字串。
分段,以指定字符为分隔符,分离出若干个子字符串,并保存在一个下标从0开始的一维数组中,其格式为:split (字符串,分隔符)
dim a="1,2,3,4,5,6,45,656465,564,45"
dim b() as integer
b=split(a,",")
那么b(0)=1
b(1)=2
b(i)=
搜索到回车符,然后用数组分段 做法参照下面
a=text1.text
dim b
b=split(a,vbcrlf)
可以将a分成以回车符分隔的一个数组。vbcrlf是回车符的常量。然后你就可以用b(0)来引用第一个回车符前的字串。
分段,以指定字符为分隔符,分离出若干个子字符串,并保存在一个下标从0开始的一维数组中,其格式为:split (字符串,分隔符)
dim a="1,2,3,4,5,6,45,656465,564,45"
dim b() as integer
b=split(a,",")
那么b(0)=1
b(1)=2
b(i)=
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询