Help and Support
 

powered byLive Search

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

Article ID:906771
Last Review:May 11, 2007
Revision:1.4
On This Page

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.

Back to the top

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.

Back to the top

WORKAROUND

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

Back to the top

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)

Back to the top

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.

Back to the top

STATUS

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

Back to the top

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 (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 (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 (http://msdn2.microsoft.com/en-us/library/aa239677(VS.60).aspx)

Back to the top


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

Back to the top

Keywords: 
kbbug kbtshoot kbprb KB906771

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by Email, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.