ASP Forum
testing for end of file
rsbblue1 | Posted 2:12am 20. April 2009 Server Time |

testing for end of file

--------------------------------------------------------------------------------

I am new to ASP programming.

I am using this code snippet to read a text file and display it on a web page.
The "alphabet.txt" file is less than 60 lines and I am trying to stop reading after the last line has been read and displayed.

Thank you

Here's the code snippet:



<%
dim i
Set fs=Server.CreateObject("Scripting.FileSystemObject ")
Set f=fs.OpenTextFile(Server.MapPath("alphabet.txt"), 1)


For i=1 to 60 step 1
' The next line is wrong but whats right ???
if not fs.eof then
Response.Write (f.ReadLine & "
")
else
end if

Next
f.Close
Set f=Nothing
Set fs=Nothing
%>
katy8439 | Posted 4:00am 20. April 2009 Server Time |

Try replacing

For i=1 to 60 step 1
' The next line is wrong but whats right ???
if not fs.eof then
Response.Write (f.ReadLine & "
")
else
end if

Next

With

Do While Not f.AtEndOfStream
   Response.Write (f.ReadLine & "")
LOOP


Reply to Post testing for end of file



Back to Forum Page