Microsoft KB Archive/906771

= You cannot use Visual Basic 2005 to read the Currency data type values back from a file =

Article ID: 906771

Article Last Modified on 5/11/2007

-

APPLIES TO


 * Microsoft Visual Studio 2005 Standard Edition
 * Microsoft Visual Studio 2005 Professional Edition
 * Microsoft Visual Studio 2005 Express Edition
 * Microsoft Visual Studio .NET 2003 Professional Edition
 * Microsoft Visual Studio .NET 2003 Enterprise Architect
 * Microsoft Visual Studio .NET 2003 Enterprise Developer
 * Microsoft Visual Studio .NET 2003 Academic Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Architect
 * Microsoft Visual Studio .NET 2002 Professional Edition
 * Microsoft Visual Studio .NET 2002 Enterprise Developer
 * Microsoft Visual Studio .NET 2002 Academic Edition

-





SYMPTOMS
Consider the following scenario:
 * You use Currency data type values inside a user-defined structure.
 * You use Microsoft Visual Basic 6.0 to write the Currency data type values to a file.

In this scenario, you cannot use Microsoft Visual Basic 2005 to read the Currency data type values back from the file.



CAUSE
This problem occurs because the Currency data type is upgraded to the Decimal data type in Visual Basic 2005. For stand-alone Decimal data types, the Visual Basic 2005 I/O reads and writes the Decimal data type values as if they were OA Currency data type values. For Currency data type values that are inside a user-defined structure, the Visual Basic 2005 I/O reads and writes the Decimal data types without trying to convert them to an OA Currency data type. This causes Visual Basic 2005 to incorrectly read the file that you wrote by using Visual Basic 6.0.



WORKAROUND
To work around this problem, use one of the following methods.

Method 1
Use Visual Basic 2005 to read the Currency data type values back from the file separately, instead of reading back the user-defined structure. For example, use the following code. Dim currencyValue As Decimal FileGet(1, currencyValue) MsgBox(currencyValue)

Method 2
Use an Int64 value inside the user-defined structure. Then, use the Decimal.FromOACurrency method to retrieve the Decimal data type value from the Int64 value. To do this, follow these steps:   Use the following code to create a structure that uses an Int64 value. Private Structure TypeWithCurrency Public c As Int64 End Structure   Use the following code to read in the file, and then retrieve the Decimal data type value from the Int64 value. Dim t1 As TypeWithCurrency

FileGet(1, t1) FileClose(1)

Dim currencyValue As Decimal = Decimal.FromOACurrency(t1.c) MsgBox(currencyValue) 

Note You cannot use Visual Basic 2005 to write the values to the file and then to read the values back from the file by using method 2. If you use Visual Basic 2005 to write the values to the file, the values will be in the Decimal data type instead of in the Currency data type. Method 2 can only be used to modify the file one time.



STATUS
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the &quot;Applies to&quot; section.



MORE INFORMATION
For more information, visit the following Microsoft Developer Network (MSDN) Web sites:

FileGet function

http://msdn2.microsoft.com/en-us/library/3acfheek(vs.71).aspx

Structure declaration changes in Visual Basic

http://msdn2.microsoft.com/en-us/library/030kb3e9(vs.71).aspx

Migrate your VB6 code to VB .NET

http://msdn2.microsoft.com/en-us/library/aa239677(VS.60).aspx

Keywords: kbbug kbtshoot kbprb KB906771

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.