要将一个文本文件分行读入数组,但不知道有多少行数,不能dim数组的下标,我的问题是:如何知道文本文件有多少行,以此来界定数组下标?先line input读一遍不算。

解决方案 »

  1.   

    你可以用do while如open <filename> for input as #1
    do while not eof(1)
       Line Input #1, att(i)
    loop 
    close #1
      

  2.   

    FileOpen(1, "C:\start.txt", OpenMode.Input)
            While Not EOF(1)
                Input(1, s)
            End While
            FileClose(1)这个是vb.net的 转换一下应该就可以了
      

  3.   

    提供思路:在文本文件中查找vbCrLf的个数,加上1就是文本文件的行数。
      

  4.   

    我的想法是有没有这样一个函数,可以fun("abc.txt")就能得到该文件的行数,而不是先读一遍。查找vbcrlf的个数与读一遍异曲同工了。
      

  5.   

    vb里不象c那样开始时候必须定义数组的下标,你可以用动态数组。参考代码Dim MyArray() As String
    Dim strFileName As String
    Dim i As Integer, filenumber As IntegerstrFileName = "C:\111.txt"filenumber = FreeFileOpen strFileName For Input As #filenumber
        
        i = 1
        Do Until EOF(filenumber)
            
            Input #filenumber, strBuffer
            ReDim Preserve MyArray(i)
            MyArray(i) = strBuffer
            Debug.Print MyArray(i)
            i = i + 1
        LoopClose #filenumber