Leverage the .NET Framework with Visual Basic.NET

DataTypes & Operators

Data Types

The following is based on the preliminary VB.Net documentation:

VB type .NET type Size Range
Boolean System.Boolean 4 bytes True/False
Byte System.Byte 1 byte 0-255 (unsigned)
Char System.Char 2 bytes 0-65535 (unsigned)
Date System.DateTime 8 bytes 01-Jan-0001 to 31-Dec-9999
Decimal System.Decimal 12 bytes 28 digits
Double System.Double 8 bytes +/-1.797E308
Integer System.Int32 4 bytes +/-2.147E9
Long System.Int64 8 bytes +/-9.223E18
Object System.Object 4 bytes Any Type
Short System.Int16 2 bytes -32,768 to 32,767
Single System.Single 4 bytes +/-3.402E38
String System.String 10 bytes + (2 * CharacterCount) 2 billion characters
Structure (Inherits from System.ValueType) Sum of members Sum of members

Notes

  • VB.Net can also define variables using the .NET names as in:
    Dim x As Int32
    Dim u As UInt16 ' Unsigned 16-bit integer
  • Note that math operations are not supported on unsigned values
    Dim b As SByte ' Signed byte
  • The Single and Double types are standard floating point formats and subject to the inherent accuracy issues. For example, 3.5+0.5=3.9999999999999999.....
  • The Decimal type may be a better choice for some applications.
  • Currency is no longer supported and the Decimal type is usually the best substitute.
  • Variant is no longer supported although Object can now be used to hold any type.
  • User-defined types have been replaced by structures.
  • The Date type is no longer stored as a Double so direct manipulation is not permitted.

Arithmetic Operation Shortcuts

VB.Net supports a shorthand syntax for arithmetic operations that will be familiar to any C programmer but may seem a little strange to non-C programmers.

Using this shortened syntax allows expressions like x=x+1to be written as x+=1. In general, the syntax

{variable} = {variable} {operator} {expression}

is shortened to:

{variable} {operator} = {expression}

Some more examples to help clarify:

Standard syntax Shortened syntax
x = x + y x += y
x = x - z x -= z
x = x * 2 x *= 2
x = x ^ 3 x ^= 3
x = x / k x /= k
s1 = s1 & s2 s1 &= s2

Note that the "standard" syntax is still valid and that the new syntax is simply another option.

You might also like...

Comments

About the author

G.Gnana Arun Ganesh

G.Gnana Arun Ganesh India

G.Gnana Arun Ganesh is the Administrator and the Founder of ARUN MICRO SYSTEMS (www.arunmicrosystems.netfirms.com). He has been programming in C++, Visual Basic, COM, Java and Microsoft Technolo...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”