HP3000-L Archives

February 2010, Week 3

HP3000-L@RAVEN.UTC.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Greg Terterian <[log in to unmask]>
Reply To:
Date:
Fri, 19 Feb 2010 13:52:11 -0500
Content-Type:
text/plain
Parts/Attachments:
text/plain (49 lines)
Public Function ConvertFromCOBOLSignedNumberToDouble(ByVal signedNumber As String, ByVal decimalPlaces As Integer) As Double
        ' COBOL Signed Number Converter
        Dim codeChar As String
        Dim convertedNumber As Double
        Dim codeCharsPositive As String = "{ABCDEFGHI"
        Dim codeCharsNegative As String = "}JKLMNOPQR"
 
        signedNumber = signedNumber.Trim
 
        If signedNumber = String.Empty Then
            Return 0
        End If
 
        codeChar = signedNumber.Substring(signedNumber.Length - 1)
 
        If codeCharsPositive.IndexOf(codeChar) > -1 Then
            ' For Positive Numbers, the last digit is converted from
            ' "{ABCDEFGHI" to "0123456789" respectively.
 
            signedNumber = signedNumber.Substring(0, signedNumber.Length - 1) & codeCharsPositive.IndexOf(codeChar)
 
            convertedNumber = Convert.ToDouble(signedNumber)
 
        ElseIf codeCharsNegative.IndexOf(codeChar) > -1 Then
            ' For Negative Numbers, the last digit is converted from
            ' "}JKLMNOPQR" to "0123456789" respectively.
 
            signedNumber = signedNumber.Substring(0, signedNumber.Length - 1) & codeCharsNegative.IndexOf(codeChar)
 
            convertedNumber = -Convert.ToDouble(signedNumber)
 
        Else
            ' Not a COBOL Signed Number, but still apply decimal places
            convertedNumber = CDbl(signedNumber)
        End If
 
        If decimalPlaces > 0 Then
            Return convertedNumber / (10 ^ decimalPlaces)
        Else
            Return convertedNumber
        End If
    End Function




* To join/leave the list, search archives, change list settings, *
* etc., please visit http://raven.utc.edu/archives/hp3000-l.html *

ATOM RSS1 RSS2