Microsoft KB Archive/267925

= PRB: Opening Binary File for Input Returns Only One Character =

Article ID: 267925

Article Last Modified on 9/4/2002

-

APPLIES TO


 * Microsoft eMbedded Visual Basic 3.0

-



This article was previously published under Q267925



SYMPTOMS
In an eMbedded Visual Basic application, if you open a file in Binary mode and use the Input function to read the file, only one character is returned, regardless of how many characters you specified.



CAUSE
When you use the Put method to write data to a file, the data is implicitly written as Variant data. Because it is Variant data and must be able to be read back in from the file, the Put method parses the Variant data to determine what kind of data it is and how big it is. This information is written out to the file along with the data; thus, according to the illustration in the &quot;More Information&quot; section, the type of data is VT_BSTR (0800) and the length is 5 bytes (0005).

If you use the Input method to read the data back in, when you specify the number of bytes to read, and you get whatever is there. According to the scenario in the &quot;More Information&quot; section, you read 5 bytes, which consist of the 4 byte header in the BSTR structure and the letter &quot;T.&quot; The Input method does not allow you to specify the number of bytes to read; instead, you provide a list of Variant variables, and it decodes for you.



RESOLUTION
To read what you just wrote out, use the Get method instead of the Input method. To do this, replace the following line in the &quot;More Information&quot; section result = File1.Input(5) with this line: File1.Get result



STATUS
This behavior is by design.



Steps to Reproduce Behavior
 Start a new Windows CE project in eMbedded Visual Basic. Form1 is created by default. From the Project menu, click Components, and then select the Microsoft CE File System Control check box. Place a list box, a command button, a file system control, and a file control on Form1.  Paste the following code into Form1: Private Sub Command1_Click Dim result File1.Open &quot;Binary.txt&quot;, fsModeBinary File1.Put &quot;Test1&quot; File1.Put &quot;Test2&quot; File1.Close File1.Open &quot;Binary.txt&quot;, fsModeBinary result = File1.Input(5) File1.Close List1.AddItem result FileSystem1.Kill &quot;Binary.txt&quot; End Sub  Click the command button. All that is returned to the ListBox is a small white box.</li></ol>

Additional query words: evb fso filesystemobject

Keywords: kbprb KB267925

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.