Microsoft KB Archive/142246

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

Article ID: 142246

Article Last Modified on 5/7/2003

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Learning Edition
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
 * Microsoft Visual Basic for Applications 5.0

-



This article was previously published under Q142246



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
 Start Visual Basic 4.0, or if it is already running, click New Project on the File menu. Add a command button to Form1.  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  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.

