I wrote this which seems to work.
Public Class OpenRandomFiles
Private fs As FileStream, sr As BinaryReader
Friend Sub New(ByVal fPath As String)
fs = New FileStream(fPath, FileMode.Open, FileAccess.Read, FileShare.Read)
sr = New BinaryReader(fs)
End Sub
Friend Sub Dispose()
sr.Close()
fs.Dispose()
End Sub
#Region " Properties "
Private fCount As Integer
Friend ReadOnly Property Count() As Integer
Get
Return fCount
End Get
End Property
Private fStrings() As String
Friend ReadOnly Property Strings() As String()
Get
Return fStrings
End Get
End Property
Private fWidths(), wCount As Integer
Friend WriteOnly Property Widths() As Integer()
Set(ByVal value As Integer())
fWidths = value
wCount = UBound(fWidths)
ReDim fStrings(wCount)
Dim w As Integer = 0
For i As Integer = 0 To wCount
w += fWidths(i)
Next
fCount = CInt(fs.Length \ w - 1)
End Set
End Property
#End Region
Friend Function ReadLine() As Boolean
Try
For i As Integer = 0 To wCount
Dim b() As Byte = sr.ReadBytes(fWidths(i))
fStrings(i) = ""
For k as Integer = 0 To UBound(b)
fStrings(i) = Chr(b(k))
Next k
Next
Return False
Catch ex As Exception
Return True
End Try
End Function
End Class
It works like this
Dim l() As Integer = {1, 40, 40, 40, 40, 40, 40, 20, 20, 20, 20, 20, 60, 5, 4, 1, 2, 1, 1}
Dim f As New OpenRandomFiles(MailFile)
f.Widths = l
MailK = f.Count
ReDim Mail(MailK)
For i As Integer = 0 To MailK
f.ReadLine()
Dim s() As String = f.Strings
With Mail(i)
.Flag = Asc(s(0))
.Name = s(1)
.Spare1 = FnAsc(s(14))
.Spare2 = Asc(s(15))
End With
Next
f.Dispose()