I need to write a lot of Long values to a file fast.
If I use Write, a Long value will use 8 characters in the
file. I have prepared a module to convert a Long value
to a 3 character string for writing to a file (and convert it back again).
Is this ok? It works fine but is there a better, less messy way?
Also I don't want to use binary mode as it is painfully slow.
Code:Public Function ThreeByteStringFromLong(lngNumber As Long) As String ThreeByteStringFromLong = Chr(R(lngNumber)) + Chr(G(lngNumber)) + Chr(B(lngNumber)) End Function Public Function LongFromThreeByteString(str3Byte As String) As Long Dim strA As String Dim strB As String Dim strC As String strA = Left(str3Byte, 1) strB = Mid(str3Byte, 2, 1) strC = Right(str3Byte, 1) LongFromThreeByteString = RGB(Val(strA), Val(strB), Val(strC)) End Function Private Function R(lColor As Long) As Byte R = lColor And &HFF& End Function Private Function G(lColor As Long) As Byte G = Int(lColor / &H100&) And &HFF& End Function Private Function B(lColor As Long) As Byte B = Int(lColor / &H10000) And &HFF& End Function




Reply With Quote