ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how do you skip lines when reading a text file (https://www.excelbanter.com/excel-programming/275631-how-do-you-skip-lines-when-reading-text-file.html)

Yaw Bonsu

how do you skip lines when reading a text file
 
Open Strfilename For Input As #iFile
i = 1
Do While Not EOF(iFile)
e = Input(1, #iFile)
z = ""
Do While Not (e = Chr(13) or e = Chr(13)+Chr(10))
z = z & e
e = Input(1, #iFile)
Loop
'Input #iFile, z 'original code begins on this
line
Range("Sheet1!a" & i).Value = z
*** Go to the next line in input...(how do I code that?)
'Input #iFile, z
'Range("Sheet1!b" & i).Value = z
'i = i + 1 'original code ends on this line
Loop
Close #iFile
Exit Sub

Using the code above, I'm trying to skip to the next line in the input
file, the code abov runs a never-ending loop and reads the same line
over and over again. Please help.

Tom Ogilvy

how do you skip lines when reading a text file
 
Sub ReadFile()
Dim strFileName As String
Dim i As Long
Dim sLine As String
Dim ifile As Long
strFileName = "C:\data\eclipse.txt"
ifile = FreeFile()
Open strFileName For Input As #ifile
i = 1
Do While Not EOF(ifile)
Line Input #ifile, sLine
Debug.Print i, sLine
i = i + 1
Loop
Close (ifile)
End Sub


--
Regards,
Tom Ogilvy

"Yaw Bonsu" wrote in message
om...
Open Strfilename For Input As #iFile
i = 1
Do While Not EOF(iFile)
e = Input(1, #iFile)
z = ""
Do While Not (e = Chr(13) or e = Chr(13)+Chr(10))
z = z & e
e = Input(1, #iFile)
Loop
'Input #iFile, z 'original code begins on this
line
Range("Sheet1!a" & i).Value = z
*** Go to the next line in input...(how do I code that?)
'Input #iFile, z
'Range("Sheet1!b" & i).Value = z
'i = i + 1 'original code ends on this line
Loop
Close #iFile
Exit Sub

Using the code above, I'm trying to skip to the next line in the input
file, the code abov runs a never-ending loop and reads the same line
over and over again. Please help.





All times are GMT +1. The time now is 08:12 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com