注册 登录
编程论坛 VB6论坛

下列代码只能得到text1中的总行数,如何得到第n行的数据呢?求指教。。

liu0033546 发布于 2013-04-03 18:33, 432 次点击
Const EM_GETLINE = &HC4
Const EM_LINELENGTH = &HC1
Const EM_LINEINDEX = &HBB
Const EM_GETLINECOUNT = &HBA
 


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 Sub Command1_Click()

Text2.Text = SendMessage(Text1.hWnd, EM_GETLINECOUNT, 0&, 0&)

End Sub
3 回复
#2
风吹过b2013-04-03 19:07
我不会用API。

Public Function getstr(str1 As String, index As Long) As String
Dim fj() As String
fj = Split(str1, vbCrLf)          '分解成一行一行
If index>0 and index < UBound(fj)+2 Then      '在总行数的范围内
    getstr = fj(index - 1)        '取结果
Else                              '否则返回空
    getstr = ""                  
End If
End Function
#3
bczgvip2013-04-03 20:21
程序代码:

Public Function Edit_GetLine(ByVal hWndControl As Long, ByVal nLine As Long) As String
    Dim nRet As Long
    ReDim bTmp(1024) As Byte
    bTmp(1) = 4
    nRet = SendMessage(hWndControl, &HC4, nLine, bTmp(0))
    If nRet Then
        Edit_GetLine = StrConv(Left$(bTmp, InStr(1, bTmp, vbNullChar) - 1), vbUnicode)
        'Edit_GetLine = Left$(bTmp, nRet) 'unicode SendMessageW
    End If
End Function
#4
liu00335462013-04-03 22:17
回复 2楼 风吹过b
谢谢
1