How to read complete lines in text file

D

DianePDavies

I want to read a text file line by line:

Open "C:\TestFile.TXT" For Input As #1
count = 0
Input #1, InputString
While Not EOF(1)
count = count + 1
Input #1, InputString
Wend

If there is a comma in my text line, it is read as two lines...?

How do I avoid that?
 
S

Stefan Hoffmann

hi Diane,
I want to read a text file line by line:

Open "C:\TestFile.TXT" For Input As #1
count = 0
Input #1, InputString
While Not EOF(1)
count = count + 1
Input #1, InputString
Wend

If there is a comma in my text line, it is read as two lines...?
You need to use

Line Input #1, lineString

btw, you should use FreeFile:

Dim Count As Long
Dim FileHandle As Long

LineCount = 0
FileHandle = FreeFile

Open "C:\TestFile.TXT" For Input As #FileHandle
Input #FileHandle, InputString
Do While Not EOF(#FileHandle)
LineCount = LineCount + 1
Line Input #FileHandle, InputString
Loop
Close #FileHandle


mfG
--> stefan <--
 

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