I am trying to convert a VB.6 program to VB .Net 2005. The program reads up fixed length records from a file and does stuff with them. The code to read the file and load up a combobox looks something like this (sorry about the double-spacing ... don't know how to avoid it):
fPayees = FreeFile
FileOpen(fPayees, gMasterPayeeDatabaseFile, OpenMode.Random, , , Len(PayeeData))i = Len(HistoryItem)
i = LOF(fPayees)
j = Len(PayeeData)
intTotPayeeRecs = LOF(fPayees) / Len(PayeeData)
For j = 1 To intTotPayeeRecs ' Display all payees in payee databaseFileGet(fPayees, PayeeData, j)
cboPayee.Items.Add((Trim(PayeeData.Payee)))
strPayee(j) = Trim(PayeeData.Payee)
strAmount(j) = Trim(PayeeData.Amount)
strMemo(j) = Trim(PayeeData.Memo)
strDate(j) = Trim(PayeeData.DateEntered)
Next jNow PayeeData is defined as an instance of a structure which is defined as:
Private Structure PayeeRecord<VBFixedString(20), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=21)> Public DateEntered() As Char
<VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=2)>
Public Space1() As Char<VBFixedString(12), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=13)>
Public Amount() As Char<VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=2)>
Public Space2() As Char<VBFixedString(30), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=31)>
Public Memo() As Char<VBFixedString(1), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=2)>
Public Space3() As Char<VBFixedString(50), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=51)>
Public Payee() As Char<VBFixedString(2), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=3)>
Public CRLF() As Char End Structure
lMy problem is that len(PayeeData) does not return the proper length ... the sum of the field lengths in the PayeeRecord structure is 117. Len(PayeeData) returns 32!
Can someone help me understand this Many thanks.

Finding length of structured data
Paige Ake
Thanks ... that solved my problem. In converting the VB 2005 Upgrade Wizard converted the fields in the structure that I had set up as Strings to type Char ... not sure why and that was what caused the confusion. I converted them all back to Strings (as you suggested) and it worked fine. Go figure!
stridulence
hgen_banks ... Thanks for the very helpful reply.
MightyDubCats
My recommendation would be to rewrite the structure to use regular strings. This will require rewriting any code that reads or writes files with these structures using either a BinaryReader/BinaryWriter or just using the FileStream directly to read a fixed number of bytes. You may be able to avoid this though, since it looks as though each record ends with a new line, in which case you can you StreamReader.ReadLine and pull set size substrings from each line.
John Stallo MSFT
When I converted a VB6 program and it did that, I changed each of the structure's strings to elements like:
<VBFixedString(30)>
Public CoName As StringThen the rest of the code (and LEN statement) worked.