# sorry 少加了几行 code, 请入内看

Posted by Albert on August 18, 1999 at 10:57:58:

In Reply to: Why !? 我用如下的 code, but run time 时会有 语法错误 at : Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String posted by Albert on August 18, 1999 at 10:55:21:

Private Sub Command1_Click()
Dim str5 As String
Dim LineCnt As Long

LineCnt = TextBoxLineCnt(Text1)
str5 = GetaLine(Text1, LineCnt) '取得第二行的字串，以0为基底

Debug.Print str5
End Sub

: Option Explicit
: Const EM_GETLINE = &HC4
: Public Const EM_GETLINECOUNT = &HBA
: 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

:
: Option Explicit
: Public Function TextBoxLineCnt(ctl As TextBox) As Long
: TextBoxLineCnt = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, 0)
: End Function

Follow Ups: