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



The information in this article 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 Edition
  • Microsoft Visual Studio .NET (2003), Enterprise Developer Edition
  • Microsoft Visual Studio .NET (2003), Academic Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Architect Edition
  • Microsoft Visual Studio .NET (2002), Professional Edition
  • Microsoft Visual Studio .NET (2002), Enterprise Developer Edition
  • 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:
  1. Use the following code to create a structure that uses an Int64 value.
    Private Structure TypeWithCurrency
    	Public c As Int64
    End Structure
  2. 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 "Applies to" section.

MORE INFORMATION

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

Modification Type:MajorLast Reviewed:12/9/2005
Keywords:kbBug kbtshoot kbprb KB906771 kbAudDeveloper