BUG: Sequential File I/O Does Not Handle Embedded Nulls

Last reviewed: January 12, 1996
Article ID: Q142246
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

Using sequential file I/O to read in file that contains embedded null characters (characters with an ANSI value of 0) can cause Visual Basic 4.0 to generate the following error message, "Run-time error '62': Input past end of file".

STATUS

Microsoft has confirmed this to be an issue in the Microsoft products listed at the beginning of this article. Microsoft is researching this issue and will post new information here in the Microsoft Knowledge Base as it becomes available.

WORKAROUND

You can work around this behavior by opening the sequential file as a binary file and manipulating the sequential file as a binary file using the Get and Put statements to set and retrieve file data.

MORE INFORMATION

The code sample shown creates a one dimensional byte array with ten elements and fills the array with the number 65 except for the eighth element. This element contains the number 0--a null character. When you run this program, an error message is displayed.

Steps to Reproduce

  1. Start Visual Basic 4.0, or if it is already running, click New Project on the File menu.

  2. Add a command button to Form1.

  3. Add the following code to the Form1 code window:

          Private Sub Command1_Click()
    
             Close
             Dim b(10) As Byte
    
             'Assign the following numbers to the array elements.
             b(0) = 65
             b(2) = 65
             b(4) = 65
             b(6) = 65
             b(8) = 0
    
             'Set the byte value to a string variable
             s$ = b
    
             'Send the contents of string variable to a sequential file
             Open "C:\test.dat" For Output As #1
             Print #1, s$
             Close #1
    
             'Open the file to receive data
             Open "C:\test.dat" For Input As #1
             t$ = Input(LOF(1), #1)
             Close #1
          End Sub
    
    

  4. Press the F5 key to start the program. The error, "Run-time error'62': Input past end of file" displays. This error is raised when using the Input function to read the contents of the file.

REFERENCES

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

   ARTICLE-ID: Q140354
   TITLE     : BUG: Input Function Doesn't Ignore EOF


Additional reference words: 4.00 vb4win vb4all sequential file
KBCategory: kbprg kbbuglist
KBSubcategory: PrgOther



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 12, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.