Reading a text file line by line

G

Guest

Hi there,

I'm trying to loop through a text file, processing each line of the file
depending on the values it contains.

Here's what I've got so far, all those bits don't need to be per line, they
apply to the whole file.

So my question is, how can I loop on the line number of the file?

Sub fdsa()
Dim FileNumber As Integer, FileLength As Integer, FilePath As String,
FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As FileNumber
FileLength = LOF(FileNumber)

FullString = Input(FileLength, FileNumber)
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, Chr(9), "")
MsgBox FullString, vbInformation + vbOKOnly

FullString = Replace(FullString, ".00", "")
MsgBox FullString, vbInformation + vbOKOnly

Close #FileNumber
End Sub


Cheers,
Foss
 
T

Tom Ogilvy

Sub fdsa()
Dim FileNumber As Integer, FilePath As String
Dim FullString As String
FilePath = "C:\The Export 2.txt"
FileNumber = FreeFile
Open FilePath For Input As #FileNumber
FileLength = LOF(FileNumber)
Do While Not EOF(FileNumber)
Line Input #FileNumber, FullString
MsgBox FullString, vbInformation + vbOKOnly

Loop
Close #FileNumber
End Sub
 
E

Ed

Foss:

I would consider using Word rather than Excel. If you opened the document
in Word, the Word object model allows you to select a line at a time. Word
also has a built-in EndOfDocument (EndOfFFile ??) bookmark; you can use this
to loop through -
Do
Select Line
Code Here
Loop Until End bookmark found.

HTH
Ed
 
G

Guest

Ed,

Thanks very much, although to be honest it wasn't intended to run in either.
It'll be running in Business Objects. I was posting here because I always get
the answers I want!

Thanks though, I'll use that one in Word next time I need to.

Cheers,
Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top