PRB: Converting MBF to IEEE in Visual Basic for WindowsLast reviewed: January 21, 1998Article ID: Q140520 |
4.00
WINDOWS
kbprg kbfile kbprb
The information in this article applies to:
SYMPTOMSData files created with older Microsoft Basic products (Quick Basic, GW-Basic, and Basica (IBM and Compaq licensed Basic)) may not be readable by Visual Basic for Windows.
CAUSEPrior to the IEEE floating point standard being widely accepted, Microsoft used an internal floating point format known as Microsoft Binary Format (MBF). The IEEE standard was introduced later and became the industry standard. Early versions of Microsoft QuickBASIC and GW-Basic supported only MBF format. In Microsoft Basic Professional Development System (PDS) and Visual Basic for MS-DOS, functions are available to convert between MBF and IEEE formats. As Microsoft moved toward complete acceptance of the IEEE standard, however, support for the MBF format was removed. Visual Basic for Windows uses the IEEE standard. The MBF format, however, is incompatible with the IEEE standard and data saved in this manner will not be readable.
WORKAROUNDThe PDS and Visual Basic for MS-DOS products contained functions that convert between MBF format and IEEE format. These functions are not available in Visual Basic for Windows. Here are two possible solutions to this dilemma:
STATUSThis behavior is by design.
MORE INFORMATION
Details About Method Two: Using Mbf2ieee.dllNOTE: These functions all do conversions between Microsoft Binary Format (MBF) and IEEE floating point values. Some of the newer MS-DOS-based Basic products had versions of these functions that worked differently. For example, they let you look at an IEEE number as a string without converting it to MBF. The routines described here are only provided as a way of retrieving old MBF data. These functions provide conversions between IEEE floating point values and Microsoft Binary Format (MBF) floating point values. Below is a set of declare statements which must be included in a Visual Basic program which calls these functions:
Public Declare Function Cvs Lib "MBF2IEEE.DLL" (X As String) As Single Public Declare Function Cvd Lib "MBF2IEEE.DLL" (X As String) As Double Public Declare Function Mks Lib "MBF2IEEE.DLL" (X As Single) As String Public Declare Function Mkd Lib "MBF2IEEE.DLL" (X As Double) As StringBelow is a description of each of these functions along with an example.
CVS and CVD FunctionsThese functions accept a 4-byte (CVS) or 8-byte (CVD) string as an argument. They expect the bit pattern of this string to represent a single or double precision MBF value, respectively. The function returns an IEEE result.
Dim MBF As String, IEEE As Single ' load the string from a file, etc. IEEE = CVS(MBF) MKS and MKD FunctionsThese functions accept an IEEE single (MKS), or double (MKD) precision value as an argument. It then converts this value into a 4-byte or 8-byte MBF value and returns it in a string.
Dim MBF AS String, IEEE As Single MBF = MKS(IEEE) ' Now write the MBF value out to disk Potential ProblemsThere are differences between the IEEE format and MBF. For this reason precision may be lost during the translations. It is also possible that a number cannot be converted between the two formats. If this is the case, a Visual Basic Overflow (Error #6) is generated. This is a trappable error, so handle the error accordingly.
How to Get Mbf2ieee.dllThe following file is available for download from the Microsoft Software Library:
~ mbf2ieee.exe (size: 25002 bytes)For more information about downloading files from the Microsoft Software Library, please see the following article in the Microsoft Knowledge Base:
ARTICLE-ID: Q119591 TITLE : How to Obtain Microsoft Support Files from Online ServicesAfter downloading Mbf2ieee.exe, run it to obtain Mbf2ieee.dll along with the source files and a Mbf2ieee.txt file, which is a readme that contains the text of this article.
Source Code Included in Mbf2ieee.exeIn addition to the .dll itself, the source code is also provided, so you can make modifications and recompile if you have Microsoft C. To recompile and build a new .DLL file, you must use Microsoft C because the routines are specific to Microsoft C and rely on the way Microsoft C returns floating point Values. This source code does not compile with Borland C. To recompile with Microsoft C, use the following command line statements to build the DLL:
cl -ALw -Ow -W2 -Zp -Tp mbf2ieee.c link /nod c:\vb\cdk\vbapi.lib mbf2ieee, mbf2ieee.dll, NUL, sdllcew oldnames libw, mbf2ieee rc -t mbf2ieee.dll implib mbf2ieee.lib mbf2ieee.def |
KBCategory: kbprg kbfile kbprb
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |