oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

VB.NET Data Types

by Budi Kurniawan

The new version of Visual Basic, VB7 (or VB.NET), is a big jump from VB6. With VB7 you can use the type library in the .NET Framework, and your applications run on the Microsoft .NET Framework Common Language Runtime (CLR).

There are also a number of changes from the previous versions. VB7 now supports inheritance and has a new error-handling mechanism. As part of the .NET Framework, VB7 needs to update the data types for interoperability with other programming languages such as C# and C++, and with the .NET Framework and Runtime. Data types in VB7 now represent the .NET data types, which are structures in the System namespace of the .NET Framework. However, you can still use the old programming style when working with data types, because in VB7 the data types are wrappers of those .NET data types. This article shows you how you could adapt yourself to these data types.

Bad news for VB6 experts: their expertise is not really relevant in VB.NET. Expertise in VB6 was often measured by skill in programming Windows API from inside the language. This is no longer true with VB7; VB7 programmers are now required to know the numerous types in the .NET Framework. To become an expert in VB.NET, you have to start all over again.

First, of course, you need to master the many classes, interfaces and structures that are part of the .NET Framework, not to mention the many changes in the new version of the language. But you need to start somewhere, right? Understanding the new set of data types is a good place to start.

VB7 Data Types and Equivalent .NET Framework Type Structures

VB7 value data types are wrappers for the corresponding .NET Framework type structure. These structures derive from the class System.Object. In fact, System.Object is the root of all types in the .NET Framework. The following table lists the data types in VB7 and the corresponding .NET data types. Note that there are new data types that were not available in VB6, and that some of the data types in VB6 are no longer supported. The changes from VB6's integers, currencies, and variants will be explained below.

Visual Basic type .NET Runtime type structure Storage size Value range
Boolean System.Boolean 4 bytes True or False
Byte System.Byte 1 byte 0 to 255 (unsigned)
Char System.Char 2 bytes 0 to 65535 (unsigned)
Date System.DateTime 8 bytes January 1, 1 CE to December 31, 9999
Decimal System.Decimal 12 bytes +/-79,228,162,514,264,337,593,543,950,335 with no decimal point; +/-7.9228162514264337593543950335 with 28 places to the right of the decimal; smallest non-zero number is +/-0.0000000000000000000000000001
Double System.Double 8 bytes -1.79769313486231E308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486232E308 for positive values
Integer System.Int32 4 bytes -2,147,483,648 to 2,147,483,647
Long System.Int64 8 bytes -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
Object System.Object (class) 4 bytes Any type can be stored in a variable of type Object
Short System.Int16 2 bytes -32,768 to 32,767
Single System.Single 4 bytes -3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values
String System.String (class) 10 bytes + (2 * string length) 0 to approximately two billion Unicode characters
User-Defined Type (structure) (inherits from System.ValueType) Sum of the sizes of its members Each member of the structure has a range determined by its data type and independent of the ranges of the other members

.NET Framework types not available in VB.NET: SByte, UInt16, UInt32, UInt64.

Pages: 1, 2, 3

Next Pagearrow