DBman said:
I have several files I've imported from txt files and they all
contain fields that the last character is a sine character({-I) where
{=0, A=1,B=2,etc,etc. For example 0001A = 11. I have to run queriers
involving those sined fields but I have to convert them to real
numbers first. Is there a macro or some code I can use to automate
since I'm deal with several different files containing over 200k
records? Thank you in advance for help you can give me.
I'm thinking that you are dealing with values in an ASCII translation of
the zoned decimal format. If so, the translation table for the last
digit, which has the sign nybble, is this:
{ = 0, positive
A = 1, positive
B = 2, positive
C = 3, positive
D = 4, positive
E = 5, positive
F = 6, positive
G = 7, positive
H = 8, positive
I = 9, positive
}= 0, negative
J = 1, negative
K = 2, negative
L = 3, negative
M = 4, negative
N = 5, negative
O = 6, negative
P = 7, negative
Q = 8, negative
R = 9, negative
Here's a function that, I think, will make the translation for you.
'----- start of code -----
Function fncZonedToNumber(ZonedValue As Variant) As Variant
Dim strValue As String
Dim strLast As String
If IsNull(ZonedValue) Then
fncZonedToNumber = Null
ElseIf VarType(ZonedValue) <> vbString Then
fncZonedToNumber = CVErr(5) ' invalid argument
ElseIf Len(ZonedValue) = 0 Then
fncZonedToNumber = Null
Else
strLast = Right(ZonedValue, 1)
strValue = Left(ZonedValue, Len(ZonedValue) - 1)
If InStr(1, "0123456789", strLast, vbBinaryCompare) Then
strValue = strValue & strLast
ElseIf InStr(1, "ABCDEFGHI", strLast, vbBinaryCompare) Then
strValue = strValue & Chr(Asc(strLast) - 16)
ElseIf InStr(1, "JKLMNOPQR", strLast, vbBinaryCompare) Then
strValue = "-" & strValue & Chr(Asc(strLast) - 25)
ElseIf StrComp(strLast, "{", vbBinaryCompare) = 0 Then
strValue = strValue & "0"
ElseIf StrComp(strLast, "}", vbBinaryCompare) = 0 Then
strValue = "-" & strValue & "0"
Else
fncZonedToNumber = CVErr(5) ' invalid argument
Exit Function
End If
fncZonedToNumber = Val(strValue)
End If
End Function
'----- end of code -----