yogi_bear_79
10-22-2007, 06:50 AM
Why do I lose the last line of text, with this code? If I check the variable InputString, before I write my array to the worksheet it contains the last line, yet, my array doesn't contain it?
Public Sub TextReader()
Dim FileName As String, Path As String
Dim InputString As String, FileNum As Integer
CVSArray() As String
Path = "M:\TEST\"
FileName = Dir(Path & "*.txt")
Do Until FileName = vbNullString
FileNum = FreeFile ' next file number
ReDim CVSArray(0) 'clear the array
i = 0 'line counter
Open Path & FileName For Input Access Read Shared As #FileNum
Do While Not EOF(FileNum)
ReDim Preserve CVSArray(0 To i)
Line Input #FileNum, InputString
CVSArray(i) = InputString
i = i + 1 'increment line counter
Loop ' until the last line is read
NextRow = Sheets(1).Range("A65536").End(xlUp).Offset(1, 0).Row
Sheets(1).Range(Cells(NextRow, 1), Cells(NextRow, i - 1)) = CVSArray
Close #FileNum
FileName = Dir()
Loop
End Sub
Public Sub TextReader()
Dim FileName As String, Path As String
Dim InputString As String, FileNum As Integer
CVSArray() As String
Path = "M:\TEST\"
FileName = Dir(Path & "*.txt")
Do Until FileName = vbNullString
FileNum = FreeFile ' next file number
ReDim CVSArray(0) 'clear the array
i = 0 'line counter
Open Path & FileName For Input Access Read Shared As #FileNum
Do While Not EOF(FileNum)
ReDim Preserve CVSArray(0 To i)
Line Input #FileNum, InputString
CVSArray(i) = InputString
i = i + 1 'increment line counter
Loop ' until the last line is read
NextRow = Sheets(1).Range("A65536").End(xlUp).Offset(1, 0).Row
Sheets(1).Range(Cells(NextRow, 1), Cells(NextRow, i - 1)) = CVSArray
Close #FileNum
FileName = Dir()
Loop
End Sub