# Visual Basic 6: Input Past End of File ... But it isn't

**URL:** <https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321>\
**Category:** Factual Questions\
**Created:** [April 20, 2005, 10:00pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321 "2005-04-20T22:00:14Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Liberal](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@Liberal](https://boards.straightdope.com/u/Liberal)\
**Post date:** [April 20, 2005, 10:00pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/1 "2005-04-20T22:00:14Z")

</div>

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:

```auto

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:

```auto

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?

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [April 20, 2005, 11:55pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/2 "2005-04-20T23:55:52Z")

</div>

As a totally wild guess, perhaps your data is messed up and “Braveheart” contains a null byte or some control character after the “v”? It wouldn’t be obvious unless you examined the data with a binary editor. Notepad would probably eliminate any null bytes when saving.

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [April 20, 2005, 11:57pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/3 "2005-04-20T23:57:28Z")

</div>

> [@](#):
>
> after the “v”

That should be _before_ the “v”. :smack:

---

<div class="post-metadata">

**Author:** ![Digital\_Stimulus](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Digital\_Stimulus](https://boards.straightdope.com/u/Digital_Stimulus)\
**Post date:** [April 21, 2005, 1:33am UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/4 "2005-04-21T01:33:22Z")

</div>

Nothing to offer in the way of explanation beyond a suspicion of a one-time glitch. But I have to second **friedo** ’s concern about Notepad. When I was still using Windows98, I used to use it and it does (or used to anyway) some character translations that you’d not be aware of if you didn’t already know it did them. I’ve found that [vim](http://www.vim.org/) displays all the non-standard characters I’ve thrown at it.

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [April 21, 2005, 10:03am UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/5 "2005-04-21T10:03:54Z")

</div>

Are you possibly trying to open up a Unicode/UTF16/UTF32 file in a language that is not Unicode aware? I’m not sure if notepad supports Unicode but I’m guessing it saves as ASCII/UTF8 which would fix your problem. If you have the original file, try opening it up in a hex editor and checking if the NULL or EOF charecter appears right after the v.

PS: Why does your error log contain a Mel Gibson movie in it? :?

---

<div class="post-metadata">

**Author:** ![Liberal](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@Liberal](https://boards.straightdope.com/u/Liberal)\
**Post date:** [April 21, 2005, 2:18pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/6 "2005-04-21T14:18:27Z")

</div>

It’s part of a client’s username. I’ve verified that there are no null characters, and the problem is repeatable using the same dataset. […shrug…] I guess I’ll just redirect it to open Notepad with the errors file whenever that error occurs.

---

<div class="post-metadata">

**Author:** ![Shalmanese](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@Shalmanese](https://boards.straightdope.com/u/Shalmanese)\
**Post date:** [April 21, 2005, 2:29pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/7 "2005-04-21T14:29:09Z")

</div>

Could you post the hex of the 10 charecters around the v of both the working and non working version? Also, have you tried doing a diff on the 2 files?

---

<div class="post-metadata">

**Author:** ![Clothahump](https://avatars.discourse-cdn.com/v4/letter/c/51bf81/32.png) [@Clothahump](https://boards.straightdope.com/u/Clothahump)\
**Post date:** [April 21, 2005, 5:33pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/8 "2005-04-21T17:33:30Z")

</div>

There’s a chance you might have gotten a CHR(0) in the file. IIRC, that will function as an EOF marker, but it’s been a while and I stand to be corrected.

---

<div class="post-metadata">

**Author:** ![Liberal](https://avatars.discourse-cdn.com/v4/letter/l/848f3c/32.png) [@Liberal](https://boards.straightdope.com/u/Liberal)\
**Post date:** [April 21, 2005, 9:50pm UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/9 "2005-04-21T21:50:03Z")

</div>

> [@Shalmanese](#):
>
> Could you post the hex of the 10 charecters around the v of both the working and non working version? Also, have you tried doing a diff on the 2 files?

They’re both the same:

706C616365732042726176656865617274206765

---

<div class="post-metadata">

**Author:** ![Imasquare](https://avatars.discourse-cdn.com/v4/letter/i/5f9b8f/32.png) [@Imasquare](https://boards.straightdope.com/u/Imasquare)\
**Post date:** [April 22, 2005, 12:22am UTC](https://boards.straightdope.com/t/visual-basic-6-input-past-end-of-file-but-it-isnt/300321/10 "2005-04-22T00:22:50Z")

</div>

According to a similar thread in the VB Explorer forums this may be caused by a file having more than one EOF character. It looks like the way around this is to open the file in Binary mode. Anyway here is a link to the thread:

[http://p077.ezboard.com/fvisualbasicexplorerfilesfoldersdirectories.showMessage?topicID=2030.topic](http://p077.ezboard.com/fvisualbasicexplorerfilesfoldersdirectories.showMessage?topicID=2030.topic)
