Public Function funcRJust(strvalue As Variant) As Variant
Dim strBuild As String
Dim iLength As Integer
Dim i As Integer
Dim Filler As String
Dim strNumbers As String
Dim strLetters As Variant
Dim strPrefix As String
Dim strRest As Variant
'right justify drawing numbers of 10 characters or less
funcRJust = strvalue
If funcRJust & "" = "" Or Len(strvalue) > 10 Then 'ignore strings > 10 char
Exit Function
End If
If IsAlphabetic(Left(strvalue, 1), False) = True Then 'handle "E" numbers separately
If IsNumeric(Mid(strvalue, 2, 1)) = True Then
GoSub FormatENumbers
End If
Exit Function
End If
strNumbers = PatsVal(strvalue)
If strNumbers & "" <> strvalue & "" Then
strLetters = Mid(strvalue, Len(strNumbers) + 1)
Else
strLetters = ""
End If
iLength = Len(strNumbers)
strBuild = ""
For i = iLength To 1 Step -1
strBuild = Mid(strNumbers, i, 1) & strBuild
Next i
Filler = Space(10 - Len(strNumbers))
funcRJust = Filler & strBuild & strLetters
ExitProc:
Exit Function
FormatENumbers:
strPrefix = Left(strvalue, 1)
strRest = Mid(strvalue, 2)
strNumbers = PatsVal(strRest)
If strNumbers & "" <> strRest & "" Then
strLetters = Mid(strRest, Len(strNumbers) + 1)
Else
strLetters = ""
End If
iLength = Len(strNumbers)
strBuild = ""
For i = iLength To 1 Step -1
strBuild = Mid(strRest, i, 1) & strBuild
Next i
Filler = Space(10 - Len(strNumbers))
funcRJust = strPrefix & Filler & strBuild & strLetters
Return
End Function
Public Function PatsVal(str As Variant) As String
Dim strNumbers As String
Dim i As Integer
Dim ValLen As Integer
Dim EndLoop As Boolean
ValLen = Len(str)
If ValLen = 0 Then
PatsVal = ""
Exit Function
End If
EndLoop = False
i = 1
Do Until EndLoop = True
If i > ValLen Then
EndLoop = True
Else
If IsNumeric(Mid(str, i, 1)) Then
strNumbers = strNumbers & Mid(str, i, 1)
i = i + 1
Else
EndLoop = True
End If
End If
Loop
PatsVal = strNumbers & ""
End Function
Public Function PatsFindFirstNumber(str As Variant) As Integer
Dim strNumbers As String
Dim i As Integer
Dim ValLen As Integer
Dim EndLoop As Boolean
ValLen = Len(str)
If ValLen = 0 Then
PatsFindFirstNumber = 0
Exit Function
End If
EndLoop = False
i = 1
Do Until EndLoop = True
If i > ValLen Then
PatsFindFirstNumber = 0 'none found
EndLoop = True
Else
If IsNumeric(Mid(str, i, 1)) Then
PatsFindFirstNumber = i 'number found at i
EndLoop = True
Else
i = i + 1
End If
End If
Loop
End Function
Function IsAlphabetic(char As String, Optional IncludeNumbers As Boolean) As Boolean
If Len(char) <> 1 Then 'check length
IsAlphabetic = False
Exit Function
End If
If (Asc(char) >= 65 And Asc(char) <= 90) Or (Asc(char) >= 97 And Asc(char) <= 122) Then
IsAlphabetic = True
Else
If IncludeNumbers = True Then
If Asc(char) >= 48 And Asc(char) <= 57 Then '0-9
IsAlphabetic = True
Else
IsAlphabetic = False
End If
Else
IsAlphabetic = False
End If
End If
End Function