Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Data Type Changes in Visual Basic

Data Type Changes in Visual Basic

Visual Basic .NET updates data types for interoperability with other programming languages and the common language runtime. The changes affect data type declaration, usage, and conversion.

Visual Basic 6.0

In Visual Basic 6.0, you use the Deftype statements — DefBool, DefByte, DefCur, DefDate, DefDbl, DefDec, DefInt, DefLng, DefObj, DefSng, DefStr, and DefVar — to set a variable's default type.

You use the Currency data type for calculations involving money and for fixed-point calculations.

A Date is stored in a Double format using eight bytes.

If two Variant variables containing integers are multiplied, an overflow condition causes the data type of the result to be changed to Double.

You can use the LSet and RSet statements to copy a variable of one user-defined type to another variable of a different user-defined type.

Visual Basic .NET

The Deftype statements are not supported in Visual Basic .NET. Nor is the Currency data type. Instead, use the new Decimal data type, which can handle more digits on both sides of the decimal point, for all money variables and calculations. Decimal is also directly supported by the common language runtime.

In Visual Basic .NET, the Date data type uses the common language runtime DateTime data type, which is an eight-byte integer value. Because of these different representations, there is no implicit conversion between the Date and Double data types. To convert between Double and the Visual Basic 6.0 representation of Date, use the ToOADate and FromOADate methods of the DateTime structure in the System namespace.

If multiplication of two Object variables containing integers results in an overflow, the result is changed to the 64-bit Long data type.

You cannot use LSet and RSet to assign one data type to another. Doing so entails a type-unsafe operation, particularly with structures, which could result in unverifiable code.

See Also

Decimal Data Type | Date Data Type | DateTime Structure | TimeSpan Structure | Val Function | Type Conversion Functions | Data Type Summary | Double Data Type | Long Data Type | Programming Element Support Changes Summary

© 2015 Microsoft