|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Reading a binary file created with VB6files. We are shortly going to port to VB.NET (framework version 2.0) and will need to be able to read and write these binary files from .NET. The file format cannot be changed, so the .NET code will need to mimic the read/write VB6 stuff. I am am using a BinaryReader to read the data in .NET. In VB6, the data is read with "Get" and retrieved with "Put", in a file opened/created in binary mode. I am having trouble working out how VB6 stores certain types of data. Below is some VB6 code that mimics the write behaviour: Option Explicit Private Type MyAttrib sId As String End Type Private Type MyType Attribs() As MyAttrib End Type Private Sub Form_Load() Dim ff As Integer ff = FreeFile() On Error Resume Next Kill "C:\test.txt" On Error GoTo 0 Open "C:\test.txt" For Binary As ff Dim count As Integer count = 2 Dim mt As MyType ReDim mt.Attribs(count) Dim i As Integer For i = 0 To count - 1 mt.Attribs(i).sId = "Identifier " & CStr(i) Next Put #ff, , mt Close ff End Sub Note that the MyType type has an array of "MyAttrib"s. There can be any number of "MyAttrib"s. Question: how does VB6 store this array? Looking at a hex editor gives this: 01 00 03 00 00 00 00 00 00 00 0C 00 49 64 65 6E 74 69 66 69 65 72 20 30 0C 00 49 64 65 6E 74 69 66 69 65 72 20 31 00 00 The strings "Identifier 0" starts with the 49 64 65 sequence. It is preceded by two bytes that indicate the length of the string. Presumably the "01 00 03 00 00 00 00 00 00 00" sequence tells VB6 how long the array is. How can I use this information from .NET to work out the length of the array? Perhaps: Bytes 2 and 3 (03 00) less bytes 0 and 1 (01 00) = 2 = number of members of array. Any help would be appreciated. Sorry for the length of this post. Perhaps you can make use of this article:
http://www.codeproject.com/csharp/fastbinaryfileinput.asp and modify it to your needs. Show quoteHide quote "Mr X" <some***@somewhere.com> wrote in message news:Om1HgfuiGHA.4660@TK2MSFTNGP03.phx.gbl... > One of my employer's products, written in VB6, reads and writes binary > files. We are shortly going to port to VB.NET (framework version 2.0) and > will need to be able to read and write these binary files from .NET. The > file format cannot be changed, so the .NET code will need to mimic the > read/write VB6 stuff. > > I am am using a BinaryReader to read the data in .NET. In VB6, the data > is read with "Get" and retrieved with "Put", in a file opened/created in > binary mode. > > I am having trouble working out how VB6 stores certain types of data. > Below is some VB6 code that mimics the write behaviour: > > Option Explicit > > Private Type MyAttrib > sId As String > End Type > > Private Type MyType > Attribs() As MyAttrib > End Type > > Private Sub Form_Load() > Dim ff As Integer > ff = FreeFile() > > On Error Resume Next > Kill "C:\test.txt" > On Error GoTo 0 > > Open "C:\test.txt" For Binary As ff > > Dim count As Integer > count = 2 > > Dim mt As MyType > ReDim mt.Attribs(count) > > Dim i As Integer > For i = 0 To count - 1 > mt.Attribs(i).sId = "Identifier " & CStr(i) > Next > > Put #ff, , mt > > Close ff > End Sub > > > Note that the MyType type has an array of "MyAttrib"s. There can be any > number of "MyAttrib"s. > > Question: how does VB6 store this array? > > Looking at a hex editor gives this: > > 01 00 03 00 00 00 00 00 00 00 0C 00 49 64 65 6E 74 69 66 69 65 72 20 30 0C > 00 49 64 65 6E 74 69 66 69 65 72 20 31 00 00 > > The strings "Identifier 0" starts with the 49 64 65 sequence. It is > preceded by two bytes that indicate the length of the string. > > Presumably the "01 00 03 00 00 00 00 00 00 00" sequence tells VB6 how long > the array is. > > How can I use this information from .NET to work out the length of the > array? > > Perhaps: > > Bytes 2 and 3 (03 00) less bytes 0 and 1 (01 00) = 2 = number of members > of array. > > Any help would be appreciated. Sorry for the length of this post. > >
a vb.net equivalent to the sql IN function?
Function versus ReadOnly Property VB.NET Threading CPU Issue Images, Icons Opening a new window Help using multiple languages Convert date to number of week datagridview, using calendar control selecting a date for column Create a TreeView to display content like Explorer DataTable Question |
|||||||||||||||||||||||