Subject: How to convert MBF strings to thier respected ieee Decimal f
I wrote an accounting package back in the late 80's, early 90's that began back with Qbasic. All the Data that was saved to random accessed files using the old unsupported Microsoft Binary Format (MBF). 10 years later the firm now wants me to develop a LIBERTY BASIC version of the software. I've come to a snag in development right from the start where LB no longer supports the MBF format. There are 3 function I need, they are CVI (integer), CVS (single), CVD (Double), these convert MBF strings to thier respected ieee Decimal format. I've been searching the net for about a week trying to find a method to do this and have come up against a brick wall. if anyone is able to assist me in my problem please feel free to add your advice. Anything is better than what I've come up with so far.

Subject: Re: How to convert MBF strings to thier respected ieee Decimal f
I googled "function cvdmbf" and came up with several results. I chose one and translated it into LB. However, since I don't have an easy way to test it, the following code is untested. Please let me know if it works.
Code:
Function CVDMBF(number$)
    On Error GoTo [error]
    CVDMBF = 0
    If Len(number$) = 8 And number$ <> Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0) Then
        exponent = Asc(Right$(number$, 1)) - 128
        mantissa = Asc(Mid$(number$, 7, 1))
        sign = Int(mantissa / 128)
        mantissa = 128 + mantissa Mod 128
        CVDMBF = mantissa / 256
        For byte = 6 To 1 Step -1
            CVDMBF = CVDMBF + Asc(Mid$(number$, byte, 1)) / 256 ^ (8 - byte)
        Next byte
        CVDMBF = CVDMBF * 2 ^ exponent
        If sign Then CVDMBF = -1*CVDMBF
    End If
    Exit Function
[error]
    Notice "Unexpected error "; Err; " in CVDMBF"
End Function

EDIT: Fixed missing parens.



Last edited by Brent on Oct 10th, 2014, 8:43pm; edited 1 time in total
Subject: Re: How to convert MBF strings to thier respected ieee Decimal f
Hi,

Runs perfectly !!!!
you're great !!!!

Thank you very much !!!

Beer for everyone, Cheers !!!

Subject: Re: How to convert MBF strings to thier respected ieee Decimal f
Just missing the parenthesis...


Function CVDMBF(number$)
On Error GoTo [error]
CVDMBF = 0
If Len(number$) = 8 And number$ <> Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0)+Chr$(0) Then
exponent = Asc(Right$(number$, 1)) - 128
mantissa = Asc(Mid$(number$, 7, 1))
sign = Int(mantissa / 128)
mantissa = 128 + mantissa Mod 128
CVDMBF = mantissa / 256
For byte = 6 To 1 Step -1
CVDMBF = CVDMBF + Asc(Mid$(number$, byte, 1)) / 256 ^ (8 - byte)
Next byte
CVDMBF = CVDMBF * 2 ^ exponent
If sign Then CVDMBF = -1*CVDMBF
End If
Exit Function
[error]
Notice "Unexpected error "; Err; " in CVDMBF"
End Function


Page 1 of 1


Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum

Full Version
Powered by phpBB © phpBB Group
Design by phpBBXS.Com | Lo-Fi Mod.