Reading a binary file problem

juhah

Active member
Joined
Apr 16, 2007
Messages
28
Programming Experience
3-5
Here's my problem:

I have a binary file that has been created with Visual Basic 6. It contains structures. Every structure contain fixed length variables, like integers, longs, doubles and strings (for example: Dim TypeCode as string *3). the VB6 program reads the structures from the file with Get-method.

I have to read the same file in VB .NET 2003-application. For this I use FileGet-method. I've changed the datatypes of the variables so that they should match VB6 (integer to short and long to integer). I used proper classes to determine that they're fixed length variables.

The first two structures are read fine, but then a problem occurs: In VB6 there is an array that contains 6 same structures (Global array(5) as structure). It's read in a loop. I determined the array same way (Public array(5) as structure), but an error occurs in FileGet-method. It says "Object type cannot be converted to target type".

What to do? :confused: All variables should be as they are in VB6.
 
Another option could be using serialization.
----------
I just tried with some output from FilePut and discovered the file format is not compatible with binary serialization, so this is something you can look into when you have managed to retrieve the old data. BinaryReader can be used as mentioned. Most likely also FileGet if you can get around it, maybe you can provide some sample data and structure that feature the problem and tell which binary method that was used? Then maybe someone can find out how to read it with VB.Net.
 
Last edited:
Back
Top