Variables in Visual Basic 2010

Variables are one of the most important parts of programming. Variable is a name which is given to a specific memory location which can be used by the program. Depending on the type of the data stored in the variable, the storage of the variable differs.

Variables can store different data types from basic or primitive data types to user define data types. The value which is stored inside the variables can also change during the execution of the program or can be static during the execution.

Although; you can make a program without the use of variables, but it won’t be a good program.

Let’s start creating variables in Visual Basic

In order to create a variable in Visual Basic, you need to use the keyword (Dim).
Dim Statement: declares and allocates storage space for one or more variables.

The general syntax for creating a variable is:

For naming your variable it is necessary to know about valid characters and how to name the variable so that it may not be a keyword. At the end you must enter the type of the data you wish your variable to be.

You can assign your variable at the time of declaration or in a separate line ahead.

See Also: [button link=”” size=”default” icon=”fa-cog” side=”left” target=”” color=”9fb77b” textcolor=”ffffff”]Variables In CPlusPlus[/button]

Some examples of defining variables in a Visual Basic Program:


Integer Variables Output


Character Variables Output

Output:String Output

See Also: [button link=”” size=”default” icon=”fa-th-large” side=”left” target=”” color=”9aa9b7″ textcolor=”ffffff”]Data Types In Programming Languages[/button]

Note: The Variables always store the latest value they are given. If you store one value in a variable and then store another value in it. The second value will be displayed once you call the variable.


Integer 2 Output

You can also declare Boolean, Double and other types of data-types too. We will be covering them in the upcoming articles.

Let’s do some MATHs

Program: Write a program to add and subtract two numbers in Visual Basic.


Add & Subtract Output

Program: Write a program to multiply and divide two numbers in Visual Basic.


Multiply & Divide Output

Feel free to ask your questions and post your comments below.


  • Leave a Reply

    %d bloggers like this: