Variables in Visual Basic 2010

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:   Variables In CPlusPlus

Some examples of defining variables in a Visual Basic Program:

Output:

Integer Variables Output

Output:

Character Variables Output

Output:String Output

See Also:   Data Types In Programming Languages

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.

Output:

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.

Output:

Add & Subtract Output

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

Output:

Multiply & Divide Output

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

Previous PHP Tutorials 6: PHP Operators 2
Next Math Operators and Getting User Input in Visual Basic

About author

Bahonar Javid
Bahonar Javid 43 posts

<p>* Computer Application Student<br /> * Co-Founder of www.codejow.com<br /> * Love to code and Learn new languages<br /> * Enjoy playing football</p>

View all posts by this author →

You might also like