VB.NET Data Types

WEBINAR: On-demand webcast

How to Boost Database Development Productivity on Linux, Docker, and Kubernetes with Microsoft SQL Server 2017 REGISTER >

Understanding data and how it is represented is key to making use of it in a program. In this segment we'll walk thru VB.NETs standard data types and talk about how to make use of them. We'll also look at some of the .NET runtime utilities that make it possible to change data from one type to another. When you see the word "type" in relation to VB.NET, it essentially means a .NET class. A "data type," then, is a class used to hold or represent different data values.

You also need to have some understanding of number systems and how a computer stores information. The most basic storage element in a computer is the bit. A bit is either a one (1) or a zero (0). If you group eight bits together, you get a byte. You'll see byte used when describing how much memory a computer has, usually in either Mega (MB) or Giga (GB) bytes. The byte is also the smallest unit of memory most computers are able to address. All other data types are typically expressed in the number of bytes they require for a single value. Table 1 shows the VB.NET data types and how many bytes are required for each.




Data Type

# of Bytes




True or False






Unicode character



32-bit Floating Point Number



64-bit Floating Point Number



32-bit Signed Integer



16-bit Signed Integer



32-bit Signed Integer



64-bit Signed Integer



64-bit Signed Integer



8-bit Signed Integer



16-bit Signed Integer



16-bit Unsigned Integer



16-bit Unsigned Integer



32-bit Unsigned Integer



64-bit Unsigned Integer



Date and time of day



Decimal number

Table 1 VB.NET Data Types

Strings are probably the most common data type in terms of usage in programs. Representing a string in memory differs from one language to another. Many legacy languages represent a string in memory as an undetermined number of bytes terminated by the null character (0). VB.NET actually uses a length field to set how long the string is and does not null terminate the string. This can cause issues when passing strings between different languages if a null-terminated value is expected. VB.NET strings can also contain null characters, so this could also cause problems if you're passing that value to some other routine.

VB.NET uses the Dim reserved word to define a variable with a specific type. So, to define the variable I as an Integer you would type:

Dim I as Integer

You can also assign an initial value to a variable using the Dim statement. Here's how you would declare a variable named myPi as a Double and assign it the value of 3.1415:

Dim myPi as Double = "3.1415"

The .NET runtime includes a wide range of functions and methods for creating and manipulating strings. If you have a need to build strings from multiple pieces, you'll want to take a look at the StringBuilder class. It has been highly optimized to perform the most common string operations as quickly and efficiently as possible. To use this class, simply declare a variable as follows:

Dim myNewString as New System.Text.StringBuilder()

Once you have the variable declared, you'll have access to Intellisense within Visual Studio to show you the different methods you have access to (see Figure 1). We'll make use of this and other .NET data manipulation in future articles.

Visual Studio Intellisense
Figure 1: Visual Studio Intellisense

Related Articles


  • Option Strict

    Posted by jwooley on 05/31/2011 11:06am

    Realize that your example of initializing a double would not work with Option Strict turned On (as you should do by default to avoid these kinds of type coersion issues). Actually, to initialize a double, simply use the following: Dim num As Double = 3.1415 If you use type inference, this can be simplified to Dim num = 3.1415 If you want to make this a decimal instead, use the decimial literal: Dim num = 3.1415D For a full listing of the VB literals see http://msdn.microsoft.com/en-us/library/dzy06xhf.aspx#Y608.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date