Declaring Variables

When programming in Visual Basic, you should declare your variables because this is the default mode, and Microsoft recommends this practice strongly. If you attempt to use an undeclared variable in your code, VB 2010 will throw an exception. It will actually catch the error as soon as you type in the line that uses the undeclared variable, underlining it with a wiggly line. It is possible to change the default behavior and use undeclared variables the way most people did with earlier versions of VB.
Declaring variables with the Dim statement and the As keyword, introduces their type:

Dim age As Integer
Dim name As String

The first variable, age, will store integers, such as 30 or 35; the second variable,name, will store text. You can declare multiple variables of the same or different type in the same line, as follows:

Dim age As Integer, salary As Decimal, name As String

If you want to declare multiple variables of the same type, you need not repeat the type.Just separate all the variables of the same type with commas and set the type of the last variable:

Dim Length, Width, Height As Integer, Volume, Area As Double

This statement declares three Integer variables and two Double variables. Double variables hold fractional values (or floating-point values, as they’re usually called) that are similar to the Single data type except that they can represent non-integer values with greater accuracy.