I’ve programmed with Visual Basic for, gah, many many years. Since VB for DOS. And with various flavors of Basic going all the way back to Commodore 64. I use VB professionally, and have for ten years or so. I’ve never seen anything like this.
Right now, I’m working with some legacy code.
Ideally, I would post the actual code, but I can’t do that for several reasons, including the fact that it is proprietary (and doesn’t belong to me), plus it is very long. But I can give you a snippet. Unfortunately, the problem is reproducible only with a certain data set and with a certain error condition. I’ll try to answer whatever questions you may have.
Here’s an overview: As errors are trapped in the program, information about them, along with where they occured, when, and what values key variables had is written to a sequential file in a very standard way:
Open App.path & "\Errors.Log" For Append As FileNumber
Print #FileNumber, Now & CR & LongMessage & CR & "----------------" & CR
Close FileNumber
(CR is vbCRLF & vbCRLF)
Now, there is a secret key combination that support staff can tell a user to hit, which will open the errors log. We also use it during development and testing. And here is the essential code for opening it. Again, very very simple and standard:
Open App.path & "\Errors.Log" For Input As FileNumber
txtErrorReport.Text = StrConv(InputB(LOF(FileNumber), FileNumber), vbUnicode)
Close FileNumber
At this point, it might be important to know that none of this has ever been a problem until today. You open the error log, you read the errors, you close it, you go about your business. But today, VB gave the message “Input Past End of File” when the assignment was made to txtErrorReport.Text.
So, I put in a break-point, stopped the code at that assignment, and examined the particulars.
Filenumber = 1
LOF(Filenumber) = 1960
Printing out “InputB(1960, 1)” in debug window produced error. So I closed it and opened it again, printing only 1 byte. No problem. Using a sort of binary chop method, I went up and down and up and down, eventually settling on "InputB(1260, 1). That was the extent to which it would print. A difference of 700 bytes.
However…
That was indeed the whole file. Everything it printed out was the totality of the file. I opened Notepad to compare and make sure.
Then…
I saved it with Notepad. When I did, the problem cleared up! The file was 1960 bytes again, and printing out “InputB(1960, 1)” raised no error! Wha…!?
So, saving it with Notepad made a difference, and made it read to the real end of file (which matched the allegedly truncated file). That made me think that there was an end of file marker written to the file somehow from the particular data at that time.
But the place where the data cuts off is in the middle of a string representing a path, right between the “a” and “v” of the word “Braveheart”. Sure enough, from that “v” to the rest of the file, it is 700 bytes. There’s no end of file marker there.
Does anyone have any clue what this might be?