VB中如何读取text多行的数值? 20
前提是text可以显示多行文本,label1和label2还有label3的captoin如何分别=text1的3行文本值...
前提是text可以显示多行文本,
label1和label2还有label3的captoin如何分别=text1的3行文本值 展开
label1和label2还有label3的captoin如何分别=text1的3行文本值 展开
5个回答
展开全部
代码如下:
arr = Split(Text1.Text, vbCrLf)'将text1中的文本按照换行符分开,并放入数组arr中
Label1.Caption = arr(0)'label1标题内容赋值为数组第一个元素,即text中第一行文本
Label2.Caption = arr(1)'label1标题内容赋值为数组第二个元素,即text中第二行文本Label3.Caption = arr(2)'label1标题内容赋值为数组第三个元素,即text中第三行文本
此例中的相关延伸知识:
Split 函数返回一个包含分割符的基础上进行分隔特定数量的数组。
vbCrLf在VB中代表换行符
arr = Split(Text1.Text, vbCrLf)'将text1中的文本按照换行符分开,并放入数组arr中
Label1.Caption = arr(0)'label1标题内容赋值为数组第一个元素,即text中第一行文本
Label2.Caption = arr(1)'label1标题内容赋值为数组第二个元素,即text中第二行文本Label3.Caption = arr(2)'label1标题内容赋值为数组第三个元素,即text中第三行文本
此例中的相关延伸知识:
Split 函数返回一个包含分割符的基础上进行分隔特定数量的数组。
vbCrLf在VB中代表换行符
展开全部
text可以显示多行文本只要你设置其multiline属性为true就可以,至于label的caption属性的显示代码则是这样的:Dim TEM
TEM = Split(Text1.Text, vbCrLf)
Label1.Caption = TEM(0)
Label2.Caption = TEM(1)
Label3.Caption = TEM(2)
呵呵,已经调试过了,一切ok
TEM = Split(Text1.Text, vbCrLf)
Label1.Caption = TEM(0)
Label2.Caption = TEM(1)
Label3.Caption = TEM(2)
呵呵,已经调试过了,一切ok
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
放一个文本框,设置其multiline属性为true
然后放三个label 1 2 3
放一个按钮
代码如下:
Private Sub Command1_Click()
On Error Resume Next
Dim s() As String
s = Split(Text1.Text, vbCrLf)
Label1.Caption = s(0)
Label2.Caption = s(1)
Label3.Caption = s(2)
End Sub
然后放三个label 1 2 3
放一个按钮
代码如下:
Private Sub Command1_Click()
On Error Resume Next
Dim s() As String
s = Split(Text1.Text, vbCrLf)
Label1.Caption = s(0)
Label2.Caption = s(1)
Label3.Caption = s(2)
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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)
Sub TB_GetLine(ByVal hWnd As Long, ByVal whichLine As Long, Line As String)
Dim length As Long, bArr() As Byte, bArr2() As Byte, 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
Private Sub Command1_Click()
Dim S As String
Call TB_GetLine(Text1.hWnd, 2, S)
Label1.Caption = S
Label2.Caption = S
Label3.Caption = S
End Sub
' 假设要读取 Text1 第 5 行的数据
' 传回值 S 即等于第 5 行的数据
'( 注:TextBox 的行次是从 0 起算。)
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)
Sub TB_GetLine(ByVal hWnd As Long, ByVal whichLine As Long, Line As String)
Dim length As Long, bArr() As Byte, bArr2() As Byte, 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
Private Sub Command1_Click()
Dim S As String
Call TB_GetLine(Text1.hWnd, 2, S)
Label1.Caption = S
Label2.Caption = S
Label3.Caption = S
End Sub
' 假设要读取 Text1 第 5 行的数据
' 传回值 S 即等于第 5 行的数据
'( 注:TextBox 的行次是从 0 起算。)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
str=split(text1.text,vbcrlf)
label1.caption=str(0)
label2.caption=str(1)
label3.caption=str(2)
label1.caption=str(0)
label2.caption=str(1)
label3.caption=str(2)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询