EOF and expression test

pong

New Member
Joined
Jun 18, 2011
Messages
25
i am learning do loop and eof statement through the following
but does anybody have an idea about what the code doing
For my understanding ,the code trying to find if the "total" column exists on the first row.
but what are these "Do While Not EOF(1)
Line Input #FileNumber, Data"
why do i need them


Sub DemoWhileClause()
' Page 115 at the bottom
Open ThisWorkbook.Path & Application.PathSeparator & "Invoice.txt" For Input As #1
r = 1
Do While Not EOF(1)
Line Input #FileNumber, Data
If Not Left(Data, 5) = "TOTAL" Then
' Import this row
r = r + 1
Cells(r, 1).Value = Data
End If
Loop
Close #1
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
EOF means "End of File".
Line Input means "read the current line". I think basically it moves to the next line too, after reading the current line.

Together, this means you are reading the text file sequentially, starting with the first line, continuing one line at a time, and stopping when the file marker reaches the "EOF" position when there is no more file to read. Incidentally, an empty file would be EOF right away. So this also stops you from trying to read an empty file.

I'm sure someone can give a more technical explanation but on the whole you'll find you just get used to it as you become familiar with text file input/output.
 
Last edited:
Upvote 0
EOF means "End of File".
Line Input means "read the current line". I think basically it moves to the next line too, after reading the current line.

Together, this means you are reading the text file sequentially, starting with the first line, continuing one line at a time, and stopping when the file marker reaches the "EOF" position when there is no more file to read. Incidentally, an empty file would be EOF right away. So this also stops you from trying to read an empty file.

I'm sure someone can give a more technical explanation but on the whole you'll find you just get used to it as you become familiar with text file input/output.

This helps a lot. but what is usually entered after line input ?
 
Upvote 0
The file number, in your case, 1:

Code:
Line Input #[COLOR=red]1[/COLOR], Data
 
Upvote 0
The 1 is the file number as shg said. It is the same as in your open statement. You could have more than one file open so you have to specify which file to read from. If you opened two files at the same time the second file could be #2.
 
Upvote 0

Forum statistics

Threads
1,224,595
Messages
6,179,798
Members
452,943
Latest member
Newbie4296

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top