我现在要读一个文件,用一个数组存储文件的每一行,即a(0)存第一行,a(1)存第二行...怎么操作?

解决方案 »

  1.   

    dim a() as string
    dim str as string
    redim a(0)
    open file
    do unitl eof(filenumber)
      redim preserve a(ubound(a)+1)
      line input filenumber, str
      a(ubound(a)-1)=str
    loop
    close file
      

  2.   

    Dim fsoTxt As New FileSystemObject, tsTxt As TextStream
     Dim i As Integer
     Dim J As Integer
      
    Set tsTxt = fsoTxt.OpenTextFile(AppfileName, ForReading)
    tsTxt.ReadAll
    J = tsTxt.Line
    tsTxt.CloseSet tsTxt = fsoTxt.OpenTextFile(AppfileName, ForReading)
    For i = 0 To J - 1
    a(i) = tsTxt.ReadLine
    NexttsTxt.Close
      

  3.   

    Dim a() As String
    Dim str As String
    Dim fn As LongReDim a(0)
    fn = FreeFile
    Open App.Path + "\aa.txt" For Input As #fnDo Until EOF(fn)
        ReDim Preserve a(UBound(a) + 1)
        Line Input #fn, str
        a(UBound(a) - 1) = str
    Loop
    Close #fn这个也是可以的。