LOF Problem

I have been writing a little bit of code, which reads a text file (.txt) and passes the content to a string variable, which is then used in an email, along with a few other things. The code which reads the file is here:

fileName=“c:\File3.txt”

fileNum=Freefile()

Open fileName For Input As fileNum

Length = Lof(fileNum)

BodyText=""

BodyText = Input(Length, fileNum)

Close fileNum

Now, I have been using the above code, but I have modified one of the lines above to read:

BodyText = Input(Length/2, fileNum)

because I keep getting “Input past end of file” error. However, if I used the Length/2 I get the text perfect every time.

However the user who this was written for came back and told me that in fact they only got half the text from the file. I tried my code on their text file and I got the same result. If I changed the code to just Length and not Length/2 it worked for that 1 file only, all other txt files errored the same as above.

So basically I’d like to know why all of the text files I’ve used worked only with length/2 but this one file (it’s just text, a few paragraphs) only works with length…

All of the files I tested have no special characters.

Subject: LOF Problem

EOF and End of Line detection is dependant on specific characters in the file, even though it is a text file. The manner in which it was saved could be the problem. O/S and the type of program used to save the file can have an impact.

You could also try getting length-1.

Subject: LOF Problem

David,

   "Input past end of file" error can be avoided by adding the following code in the Error trap area. ( On Error GoTo Statements)

If Cstr(Error()) = “Input past end of file” Then

	Resume Next

End if

Raj

Subject: That is a really stupid solution…

Rajesh,

David is trying to know why the error is occurring. Your solution simply sweeps it under the carpet…

Subject: RE: LOF Problem

By using that error trap, I simply get an empty string when the Input function errors…