Office中国论坛/Access中国论坛

标题: [求助]如何取得文本文件的行数 [打印本页]

作者: zyp    时间: 2005-4-6 00:25
标题: [求助]如何取得文本文件的行数
一个文本文件中有N行,在不用readline 读取整个文件的前提下,取得整个文件的行数?

多谢指教!
作者: tmtony    时间: 2005-4-6 03:44
试试这个看看 注意: myInFile是文件名 适应大小文件  (tmtony)

Function lineCount(myInFile As String) As Long

    Dim lFileSize As Long, lChunk As Long

    Dim bFile() As Byte

    Dim lSize As Long

    Dim strText As String

    lSize = CLng(1024) * 10

    ReDim bFile(lSize - 1) As Byte

    Open myInFile For Binary As #1

    lFileSize = LOF(1)

     lChunk = 1

    Do While (lSize * lChunk) < lFileSize

         Get #1, , bFile

        strText = StrConv(bFile, vbUnicode)

        lineCount = lineCount + searchText(strText)

         lChunk = lChunk + 1

    <st1:place>Loop</st1:place>

   ReDim bFile((lFileSize - (lSize * (lChunk - 1))) - 1) As Byte

    Get #1, , bFile

    strText = StrConv(bFile, vbUnicode)

    lineCount = lineCount + searchText(strText)

    Close #1

    lineCount = lineCount + 1

End Function


作者: zyp    时间: 2005-4-6 04:51
谢谢站长,先试试




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3