Sub ConvertRecord(ByRef B() As Byte, RecordStart As Long, S As Worksheet, T As Worksheet, CurRow As Long)
Dim V As Variant
Dim CurCol As Long
Dim ColumnType As String
Dim Pointer As Long
CurCol = 1
Do
ColumnType = S.Cells(CurCol + 1, 2).Value
If ColumnType = "" Then
Exit Sub
End If
Pointer = RecordStart + S.Cells(CurCol + 1, 7).Value
Select Case ColumnType
Case "DECIMAL":
V = ConvertDecimal(B, Pointer, S.Cells(CurCol + 1, 4).Value, S.Cells(CurCol + 1, 5))
Case "CHAR":
V = ConvertString(B, Pointer, S.Cells(CurCol + 1, 3).Value)
Case "SMALLINT":
V = ConvertSmallInt(B, Pointer)
Case Else:
V = CVErr(xlErrNA)
End Select
T.Cells(CurRow, CurCol).Value = V
CurCol = CurCol + 1
Loop Until False
End Sub
Function ConvertDecimal(ByRef B() As Byte, Pointer As Long, Precision As Long, DScale As Long) As Double
Dim n As Long
Dim L As Long
Dim Multiplier As Double
For n = 0 To L - 1
ConvertDecimal = ConvertDecimal + (B(Pointer + n) \ 16) * Multiplier
Multiplier = Multiplier / 10
If (n = L - 1) Then
' sign nibble
If B(Pointer + n) Mod 16 = &HD Then
ConvertDecimal = -ConvertDecimal
End If
Else
ConvertDecimal = ConvertDecimal + (B(Pointer + n) Mod 16) * Multiplier
Multiplier = Multiplier / 10
End If
Next n
End Function
Function ConvertString(ByRef B() As Byte, Pointer As Long, Size As Long) As String
Dim n As Long
For n = 0 To Size - 1
ConvertString = ConvertString + Chr(B(Pointer + n))
Next
End Function
Function ConvertSmallInt(ByRef B() As Byte, Pointer As Long) As Integer