vb如何一行一行读取文本框
求vb代码如何一行一行读取文本框如text1有三行:123345456如何把第一行存入变量a(1),第二行存入a(2)。。。。。...
求vb代码如何一行一行读取文本框
如text1有三行:
123
345
456
如何把第一行存入变量a(1),第二行存入a(2)。。。。。 展开
如text1有三行:
123
345
456
如何把第一行存入变量a(1),第二行存入a(2)。。。。。 展开
推荐于2016-04-27 · 知道合伙人软件行家
关注
展开全部
VB6.0可以用一次读取文本框全部文本内容,然后使用Split函数来实现一行一行提取文本框行内容。
Split函数,返回一个下标从零开始的一维数组,它包含指定数目的子字符串。
实现代码:
Private Sub Command1_Click()
Dim strSj As String
Dim strSjfh As Variant
Dim i As Long
strSj = Text1
strSjfh = Split(strSj, vbCrLf)
Text2 = UBound(strSjfh) '总行数
i = InputBox("输入要读的行数", i)
MsgBox (strSjfh(i - 1))
End Sub
推荐于2016-02-04 · 知道合伙人软件行家
关注
展开全部
Option Explicit
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 CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Const EM_GETLINE = &HC4
Private Const EM_LINEINDEX = &HBB
Private Const EM_LINELENGTH = &HC1
Public Function GetLineText(ByVal handle As Long, ByVal Index As Long) As String
Dim LineText() As Byte
Dim size As Long
Dim pos As Long
pos = SendMessage(handle, EM_LINEINDEX, Index, 0)
size = SendMessage(handle, EM_LINELENGTH, pos, 0)
If size = 0 Then
GetLineText = " "
Else
ReDim LineText((size - 1) + 1)
CopyMemory LineText(0), size, 2
size = SendMessage(handle, EM_GETLINE, Index, LineText(0))
GetLineText = StrConv(LeftB(LineText, size), vbUnicode)
End If
End Function
Private Sub Command1_Click()
Dim a(1 To 3) As String
Dim i As Integer
For i = 0 To 2
a(i + 1) = GetLineText(Text1.hWnd, i)
Debug.Print a(i + 1)
Next
End Sub
Private Sub Form_Load()
Text1.Text = "aaa" & vbCrLf & "bbb" & vbCrLf & "ccc"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询