OK here is a slightly revised function. It does a little more checking.
Code:
'---------------------------------------------------------------------------------------
' Procedure : ASC_EBCD
' Author : mellon
' Date : 11-Oct-2017
' Purpose : To convert a zoned ascii value to its ebcdic equivalent
'
'Parm: strIn -- a string of digits with optional leading sign
'
' If strIn has a leftmost "-", it is negative, so use the arrNeg array to resolve the Ebcdic
' If strIn has a leftmost " " or "+", it is positive, so use the arrPos array to resolve the Ebcdic
'---------------------------------------------------------------------------------------
'
Function ASC_EBCD(strIN As Variant) As String
Dim arrPos As String
Dim arrNeg As String
Dim ChrToChange As String
10 On Error GoTo ASC_EBCD_Error
20 If Not IsNumeric(strIN) Then
30 err.Raise 5555, , "Non numeric in Parameter"
40 End If
50 If Len(strIN) = 0 Then GoTo ASC_EBCD_Error
60 strIN = Trim(strIN) 'remove any leading/trailing spaces
70 ChrToChange = Right(strIN, 1) + 1
80 arrPos = "{ABCDEFGHI" ' equates to +0123456789
90 arrNeg = "}JKLMNOPQR" ' equates to -0123456789
100 If Left(strIN, 1) = "-" Then 'we're dealing with negative numbers
110 ASC_EBCD = Left(strIN, Len(strIN) - 1) & Mid(arrNeg, ChrToChange, 1)
120 ElseIf Left(strIN, 1) = "+" Then 'there is a plus sign, remove it
130 strIN = Mid(strIN, 2)
140 ASC_EBCD = Left(strIN, Len(strIN) - 1) & Mid(arrPos, ChrToChange, 1)
150 Else 'no sign involved
160 ASC_EBCD = Left(strIN, Len(strIN) - 1) & Mid(arrPos, ChrToChange, 1)
170 End If
'Debug.Print ASC_EBCD 'for debugging
ASC_EBCD_Exit:
180 Exit Function
ASC_EBCD_Error:
190 If err.number = 424 Then
200 MsgBox "Invalid or No parameter was input" & " in line " & Erl & " (" & err.Description & ") in procedure ASC_EBCD of Module AWF_Related"
210 ElseIf err.number = 0 Then
220 MsgBox "Bad Parameter " & err.number & " in line " & Erl & " (" & err.Description & ") in procedure ASC_EBCD of Module AWF_Related"
230 ElseIf err.number = 5555 Then
240 MsgBox "Bad Parameter " & err.number & " in line " & Erl & " (" & err.Description & ") in procedure ASC_EBCD of Module AWF_Related"
250 Else
260 MsgBox "Error " & err.number & " in line " & Erl & " (" & err.Description & ") in procedure ASC_EBCD of Module AWF_Related"
270 Resume ASC_EBCD_Exit
280 End If
End Function