VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Converting Cobol COMP-3 data type to VB data type

by Richard Tremblay (1 Submission)
Category: Miscellaneous
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 15th November 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Converting Cobol COMP-3 data type to VB data type

Rate Converting Cobol COMP-3 data type to VB data type



   Dim s  As String
   
   Dim i As Long
   Dim ii As Long
   
   Dim sSign As String '+ ou -
   Dim sNumbers As String
   Dim b() As Byte
   
   On Error Resume Next
   sNumbers = ""
   sSign = ""
   
   ReDim b(1 To Len(CompData) * 2)
   ii = 1
   For i = 1 To Len(CompData)
       b(ii) = Hex(Asc(Mid$(CompData, i, 1)))
       b(ii + 1) = MidB(CompData, i, 1)
       ii = ii + 2
   Next i
   
   
   'CompData is an array of Bytes
   For i = Len(CompData) To 1 Step -1
       'Scan byte by byte
       If i = Len(CompData) Then
          'First byte is the Sign (0x0D = Neg else = Pos)
          If Right(Format$(CStr(Hex(Asc(Mid(CompData, i, 1)))), "@@"), 1) = "D" Then
             sSign = "-"
          Else
             sSign = "+"
          End If
          sNumbers = Trim(Left(Format$(CStr(Hex(Asc(Mid(CompData, i, 1)))), "@@"), 1))
       Else
          'Next bytes are numbers
          sNumbers = Trim(Left$(Format$(CStr(Hex(Asc(Mid(CompData, i, 1)))), "@@"), 1)) & Trim(Right(Format$(CStr(Hex(Asc(Mid(CompData, i, 1)))), "@@"), 1)) & sNumbers
       End If
   Next i
   
   If sNumbers = "" Then sNumbers = "0"
   s = sSign & sNumbers
   
   If Err.Number <> 0 Then s = "0"
   DeComp = s
   
End Function

Download this snippet    Add to My Saved Code

Converting Cobol COMP-3 data type to VB data type Comments

No comments have been posted about Converting Cobol COMP-3 data type to VB data type. Why not be the first to post a comment about Converting Cobol COMP-3 data type to VB data type.

Post your comment

Subject:
Message:
0/1000 characters