如何通过一个函数去判断一个文本文件有多少行!有这样的函数么,求救各位高手!

解决方案 »

  1.   

    Public Const EM_GETLINECOUNT = &HBA '计算Textbox的总行数Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
      

  2.   

    用FSO的TextStream对象,打开文件,
    每读一行,计数器加一,
    一直到AtEndOfStream为True,
    试试吧。^_^
      

  3.   

    自己写一个吧:Function hangshu(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)
    hangshu = UBound(x) + 1
    Set x = Nothing
    End Function
      

  4.   

    FSO 快些:
    Function hangshu(txtpath As String) As Long
    hangshu = 0
      Dim fso As New FileSystemObject
         Dim ts As TextStream
         Set ts = fso.OpenTextFile(txtpath)
          Do While Not ts.AtEndOfStream
         hangshu = hangshu + 1
         Loop
         ts.Close
    End Function
      

  5.   

    高手你的FileSystemObject是什么东西阿,编译不过去!
      

  6.   

    MS Runtime script 差不多吧。
      

  7.   

    Open "c:\text1.txt" For Input As 1
    Dim Num as long
    Dim strx as String
    Num = 0 
    Do Until EOF(1)
        Line Input #1, strx
        Num = Num + 1
    Loop