使用File System Object
www.applevb.com

解决方案 »

  1.   

    function GetLineCount(filename as string) as integer
      dim c as integer
      dim fn as integer
      dim str as string
      fn=freefile
      open filename for input as #fn
      while not eof(fn)
        line input #fn, str
        c=c+1
      wend
      close #fn
      GetLineCount = c
    end function
      

  2.   

    http://www.csdn.net/expert/Topic/49143.shtm
      

  3.   

      奈软 说用LINE INPUT语句。我以前也用过,一般可以,但碰到UNIX下的文件(只有换行,没有回车)就有问题了,所以还是判断换行符个数好chr(10)
      

  4.   

    icbcnbxs对
    而且文本很大的话,速度会非常慢
      

  5.   

    先谢谢各位的捧场,小弟试了奈软的方法,的确管用;另外我想试icbcnbxs兄的方法,再
    次请教,如何在代码中判断换行符chr(10)个数呢?
      

  6.   

    以二进制方式打开文件,以下代码我没有试过,反正就是这个意思吧:dim ch as string * 1
    dim c as integer
    open filename for binary as #1
    while not eof(1)
      input #1, ch
      if ch=chr(10) then c=c+1
    wend
    close #1
      

  7.   

    改良的算法,可以对付unix文件(not tested)
    function GetLineCount(filename as string) as integer
      dim c as integer
      dim fn as integer
      dim str as string
      fn=freefile
      open filename for input as #fn
      while not eof(fn)
        line input #fn, str
        c=c+Len(Replace(str, Chr(10), "aa")) - Len(str) 
      wend
      close #fn
      GetLineCount = c
    end function 
     
      

  8.   

    set fs =CReateobject("scripting.filesystemobject")
    det tetfile=fs.createtextfile("Firing_sky.txt",True")
    i=0
    while txtfile.Atendogstream=false then
    textfile.skipline
    i=I+1
    loop
    txtfile.close
      

  9.   

    更正:
    原:c=c+Len(Replace(str, Chr(10), "aa")) - Len(str) 
    改为:c=c+Len(Replace(str, Chr(10), "aa")) - Len(str) +1
      

  10.   

    多谢各位兄台的鼎力帮忙,Nicrosoft(奈软)帮我成功的解决了关于"如何计算一个文档中文本的行数"的问题,bucher(bucher)帮我解决了关于"如何读取指定第X行的文本"的问题,另
    外几位朋友也没少出力,大家都辛苦了,我以白开水代酒,先敬大家一杯(我作手状),
    “咕噜”,我喝完了,相信大家都喝得很痛快吧,既然如此,那我们还是乘着酒劲,把剩下
    的问题----"如何在VB6中动态生成一定数量的控件?"也给消灭了吧,大家冲啊,杀呀到隔壁去!!!
      

  11.   

    过年的,也该发发那个"什么什么水"啦,哎,我应该怎么给你分数啊!Tell me!