We are trying to work out a solution allowing our software to read EBCIDIC
tapes which are currently processed on a Wang VS platform. The tapes
include a significant number of packed decimal strings, which we need to
unpack to obtain the numbers they encode. I obtained a class module
from someone in the newsgroup and I can't locate them. In any
event, the class method PackedStringToDouble appears to work, but I need to
get a better understanding of the pLength and pFraction arguments. Limited
testing produced the same result unpacking a 5 character string with
pLengths from 9 to 30 and pFraction as zero (we know there are no fractions
in the number we're unpacking).

Any help offered to explain the role of these arguments would be GREATLY
appreciated.

Thanks,

Larry Goldstein
Advanswers

Public Function PackedStringToDouble(pPackedString As String, pLength As
Long, pFraction As Long) As Double
Dim tDouble As Double
Dim tDecimalStr As String
Dim tLen As Long
Dim tChar As String
Dim tSignBit As Integer
Dim tDChar As String
Dim i As Long

tLen = Len(pPackedString)
tDecimalStr = ""
tSignBit = 1
For i = 1 To tLen
tChar = Mid(pPackedString, i, 1)
If i < tLen Then
tDChar = Hex(Asc(tChar))
If Len(tDChar) = 1 Then
tDChar = "0" & tDChar
End If
tDecimalStr = tDecimalStr & tDChar
Else
tDChar = Hex(Asc(tChar))
If Len(tDChar) = 1 Then
tDChar = "0" & tDChar
End If
tDecimalStr = tDecimalStr & Left(tDChar, 1)
If Right(tDChar, 1) <> "C" Then
tSignBit = -1
End If
End If
Next i

'insert the decimal place
If (pLength - pFraction) Mod 2 = 0 Then
'if the len+frac is even, we need to account for the extra leading 0
Character added
tDecimalStr = Left(tDecimalStr, pLength - pFraction + 1) & "." &
Right(tDecimalStr, pFraction)
Else
tDecimalStr = Left(tDecimalStr, pLength - pFraction) & "." &
Right(tDecimalStr, pFraction)
End If

On Error Resume Next
tDouble = CDbl(tDecimalStr) * tSignBit

PackedStringToDouble = tDouble
End Function