Here are a couple of rough and ready functions I wrote when this came up
some time ago. ConvertSignedChar() is a helper function for
ConvIBMSignedField().
Function ConvertSignedChar(C As String) As String
'Converts a single signed character to
'digit with minus sign if needed
Dim j As Long
j = InStr("{ABCDEFGHI", C) - 1
If j >= 0 Then
ConvertSignedChar = CStr(j)
Else
j = InStr("}JKLMNOPQR", C) - 1
If j >= 0 Then
ConvertSignedChar = "-" & CStr(j)
Else
ConvertSignedChar = C
End If
End If
End Function
Public Function ConvIBMSignedField(V As Variant) As Long
'Converts variant(string) containing signed field
'Modify for other numeric types
Dim blNegative As Boolean
Dim strTemp As String
Dim strSignedChar As String
strTemp = CStr(V)
'Either first or last character is signed
If InStr("0123456789", Right(strTemp, 1)) Then
'last char is numeric so first is signed
strSignedChar = ConvertSignedChar(Left(strTemp, 1))
If Left(strSignedChar, 1) = "-" Then
strSignedChar = Mid(strSignedChar, 2)
blNegative = True
Else
blNegative = False
End If
strTemp = strSignedChar & Mid(strTemp, 2)
Else
'Last char is signed
strSignedChar = ConvertSignedChar(Right(strTemp, 1))
If Left(strSignedChar, 1) = "-" Then
strSignedChar = Mid(strSignedChar, 2)
blNegative = True
Else
blNegative = False
End If
strTemp = Left(strTemp, Len(strTemp) - 1) & strSignedChar
End If
ConvIBMSignedField = CLng(strTemp) * IIf(blNegative, -1, 1)
End Function
I receive files that include IBM numbers. The last position has
either a letter or symbol representing the last number. I need a way to
convert the symbol/letter to a number, including negatives and format it
to currency. Does anyone have any ideas?