假如这个文件不是特别大的话,可以把它一次性读入文本框,然后向这个文本框发送EM_GETLINECOUNT返回行数。

解决方案 »

  1.   

    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 Const EM_GETLINECOUNT=&HBA
    Public Const EM_GETLINE=&HC4
    在Form1的代码模块中写如下代码:
        Private Sub Command1_Click()
        '获取总行数,结果显示在文本框txtLineCount中
        txtlineCount=SendMessage(Text1.hwnd,EM_GETLINECOUNT,0,0)
    End Sub==============================================把文本文件内容读取TextBox:
    Dim TempFile As Long
    Dim LoadBytes() As ByteTempFile=FreeFile
    Open 文件名 For Binary As #TempFile
    Redim LoadBytes(1 To Lof(TempFile)) As Byte
    Get #TempFile,,LoadBytes
    Close TempFileText1.Text=StrConv(LoadBytes,vbUniCode)
      

  2.   

    Function linescount(txtpath As String) As Long
     Dim filetxt As String, x As Variant
         filetxt = String(FileLen(txtpath), " ")
         Open txtpath For Binary As 1
         Get #1, , filetxt
         Close 1
         x = Split(filetxt, vbCrLf)
         linescount = UBound(x)
    End Function