I read a binary file of 900 bytes with much informations inside.
Like this:
Dim myFile As String = txt_mydir.Text + "\MY_FILE.BIN"
If IO.File.Exists(myFile) Then
Dim fInfo As New FileInfo(myFile)
Dim numBytes As Long = fInfo.Length
Dim fStream As New FileStream(myFile, FileMode.Open, FileAccess.Read)
Dim br As New BinaryReader(fStream)
Dim data As Byte() = br.ReadBytes(CInt(numBytes))
All bytes finishes in bytearray ‘data’.
Now I have to read a numbers written with VB6 structs into that file. Structs are mine and I know what is what and where is what.
For example I need a VB.NET ‘short’ number which is at bytes 81 and 82.
Among that I have all other basic number types to get out.
How to take out desired number of bytes from ‘data’ from specific location, with exact length and get a proper number from it (short, int, double…)?
Use the methods of the
BinaryReaderto get the fields of your original structAnd so on. You must read the fields in exactly the same order as they were written to the file.
Embed it into a loop like this