PRB: Opening Binary File for Input Returns Only One Character (267925)
The information in this article 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 "More Information" 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 "More Information" section, you read 5 bytes, which consist of the 4 byte header in the BSTR structure and the letter "T." 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 "More Information" section
result = File1.Input(5)
with this line:
File1.Get result
STATUS
This behavior is by design.
Modification Type: | Major | Last Reviewed: | 9/4/2002 |
---|
Keywords: | kbDSupport kbprb KB267925 |
---|
|