Here is a typical class:-
Public Class MyClass
Private bt(1234) As Byte
#Region " Properties "
Public Property Bytes() As Byte()
Get
Return bt
End Get
Set(ByVal value As Byte())
bt = value
End Set
End Property
Public Property Access() As Integer
Get
Return bt(0)
End Get
Set(ByVal Value As Integer)
bt(0) = CByte(Value)
End Set
End Property
Public Property ChargeExpenses() As Byte
Get
Return bt(1)
End Get
Set(ByVal value As Byte)
bt(1) = value
End Set
End Property
Public Property ChargeExpensesValue() As Integer
Get
Return bt(2) + bt(3) * cn256
End Get
Set(ByVal value As Integer)
bt(3) = CByte(value \ cn256)
bt(2) = CByte(value - bt(3) * cn256)
End Set
End Property
Public Property ChargeVat() As Boolean
Get
Return bt(7) = 1
End Get
Set(ByVal value As Boolean)
If value Then bt(7) = 1 Else bt(7) = 0
End Set
End Property
Public Property Cost() As Double
Get
Return FnBytesToReal(bt, 8)
End Get
Set(ByVal Value As Double)
bt = FnRealToBytes(bt, 8, Value)
End Set
End Property
Public Property Created() As String
Get
Dim a As String
Try
a = New Date(bt(20) + l_Times.BaseYear, bt(19), bt(18)).ToShortDateString
Catch ex As Exception
Try
a = New Date(bt(18) + l_Times.BaseYear, bt(19), bt(20)).ToShortDateString
Catch ex1 As Exception
a = ""
End Try
a = ""
End Try
If a = "" Then Return CStr(Today) Else Return a
End Get
Set(ByVal Value As String)
Dim v As Date = CDate(Value)
bt(18) = CByte(v.Day)
bt(19) = CByte(v.Month)
bt(20) = CByte(v.Year - l_Times.BaseYear)
End Set
End Property
Public Property Description(ByVal Index As Integer) As String
Get
Dim k As Integer
Select Case Index
Case 0 : k = 163
Case 1 : k = 227
Case 2 : k = 291
Case 3 : k = 355
End Select
Dim a As String = Decode(bt, k, 32)
Return a.Trim
End Get
Set(ByVal value As String)
Dim k As Integer
Select Case Index
Case 0 : k = 163
Case 1 : k = 227
Case 2 : k = 291
Case 3 : k = 355
End Select
bt = Encode(bt, k, value, 32)
End Set
End Property
Now you need to read the file and put it into this class.
Start with class RandomFile
#Region " Read File "
Public Function OpenReader() As e_ioRead ' my enum
If File.Exists(fpath) Then ' fPath setup in New
Dim r As Integer
Do
Try
r += 1
fs = New FileStream(fpath, FileMode.Open, FileAccess.Read, FileShare.None)
Exit Do
Catch ex As Exception
If r > 256 Then Return e_ioRead.Lock
End Try
Loop
sr = New BinaryReader(fs)
Return e_ioRead.OK
Else
Return e_ioRead.Err
End If
End Function
Public Function ReadBytes(ByVal Record As Integer) As Byte()
Try
fs.Seek(LineWidth * Record + hk, SeekOrigin.Begin) ' linewidth is width of record x2 if using Encoding
Dim b() As Byte = sr.ReadBytes(LineWidth)
Return b
Catch ex As Exception
Return Nothing
End Try
End Function
Public Sub CloseReader()
sr.Close()
fs.Close()
fs.Dispose()
End Sub
#End Region
Now somewhere else have something like this:-
Private Function OpenforRead(ByVal path As String) As Boolean
mfs = New RandomFile(path)
Select Case mfs.OpenReader(-1)
Case e_ioRead.OK
K = mfs.Count
Return True
Case e_ioRead.Lock
MsgBox(path & " is locked!")
Case Else
K = -1
Return False
End Select
End Function
Public Function Read() As MyClass
If OpenforRead() Then
With mfs
Try
CurrentJd = New MyClass
CurrentJd.Bytes = .ReadBytes(cJob)
Catch ex As Exception
MsgBox(ex.Message)
End Try
.CloseReader()
End With
End If
Return CurrentJd
End Function
Hope you get the idea