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.
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.