Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

VISUAL BASIC IS THE BEST

Name: Anonymous 2007-02-19 12:27

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
   
    L = (Precision + 1) / 2
    Multiplier = 10 ^ (Precision - DScale - 1)
    ConvertDecimal = 0
   
    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
   
    ConvertSmallInt = B(Pointer) + B(Pointer + 1) * 256
   
End Function

Name: Anonymous 2007-02-19 19:38

One word. no line delimiters. Thread over.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List