KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

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

Article: Q142246
Product(s): Microsoft Visual Basic for Windows
Version(s): 4.00
Operating System(s): 
Keyword(s): kbGrpDSVB
Last Modified: 11-JAN-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Visual Basic Learning Edition for Windows, versions 5.0, 6.0 
- Microsoft Visual Basic Professional Edition for Windows, versions 5.0, 6.0 
- Microsoft Visual Basic Enterprise Edition for Windows, versions 5.0, 6.0 
- Microsoft Visual Basic Standard Edition, 32-bit, for Windows, version 4.0 
- Microsoft Visual Basic Professional Edition, 16-bit, for Windows, version 4.0 
- Microsoft Visual Basic Professional Edition, 32-bit, for Windows, version 4.0 
- Microsoft Visual Basic Enterprise Edition, 16-bit, for Windows, version 4.0 
- Microsoft Visual Basic Enterprise Edition, 32-bit, for Windows, version 4.0 
- Microsoft Visual Basic for Applications version 5.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 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.

RESOLUTION
==========

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:

  Q140354 BUG: Input Function Doesn't Ignore EOF

Additional query words: kbVBp400bug kbVBp500bug kbVBp600bug kbVBp kbdsd kbDSupport sequential file kbVBA500

======================================================================
Keywords          : kbGrpDSVB 
Technology        : kbVBSearch kbAudDeveloper kbZNotKeyword6 kbZNotKeyword2 kbVB500Search kbVB600Search kbVBA500 kbVBA600 kbVB500 kbVB600 kbVB400Search kbVB400 kbVBASearch kbZNotKeyword3 kbVB16bitSearch
Version           : 4.00
Issue type        : kbbug

=============================================================================

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.

Copyright Microsoft Corporation 1986-2002.