Monday 23 September 2013

How to Create Variables in VB .NET with Example

when we discuss about any thing first question is why & what?
so here our first question is why variables & what is variable?

Lets discuss about variable with example

With Visual Basic , and most programming languages ​​, it is what you do store things in memory of the computer and handling of this store. If you want to add two numbers , you put the numbers in storage areas, and " tell " Visual Basic for add. But you can not do this without variables.

Thus, a variable is a storage area of the computer's memory. Think of it like this : a variable is an empty cardboard box. Now imagine that you have a very large room and in this room , you have a whole lot of empty cardboard boxes. Each empty cardboard box is a single variable. If you want to add two numbers together , write the first number on a piece of paper and put the paper in an empty box . Enter the second number on a piece of paper and put another piece of paper in a cardboard box.

Now all your thousands of empty cardboard boxes, two of them contain pieces of paper with numbers on them . In order to help you memorize thousands of boxes that keep your numbers , put a sticker on each of the two boxes. Write " number1 " sticker on the front and " number2 " on the other label.

What did we just do ? Well, we have created a large memory space ( room and cardboard boxes ) and we set up two boxes to keep our numbers (two variables) . We also gave each variable a name (notes ), so we can remember where they are.

Now consider the following:
                                                    Dim number1 As Integer
                                                    Dim number2 As Integer

                                                     number1 = 3
                                                     number2 = 5

This is the code from Visual Basic Net. This is how to create (or declare variables) VB.

Here is a summary of the variable declaration:

Dim
    Short dimension . This is a type of variables . You represent ( or "tell " Visual Basic ) you set a variable with the words. We will meet other types of variables later, but for now just remember to start your variable declarations with Sun
number1
    This is the cardboard box and label in one. It is a variable. In other words , . Our storage area after the word Sun , the Visual Basic looking for the name of your variable. You can call your variable almost anything you want, but there are some reserved words that VB will not. It's a good idea to give your variables a name for what happens in the variable .
As Integer
    We tell Visual Basic that the variable will be a number ( integer) . Well answer alternatives to Integer later .
Number1 = 3
    The equal sign is not actually an equal sign . = Sign means assign a value . In other words, this is where you put something in your variable. We tell Visual Basic to assign a value of 3 to variable called number1 . Think of a sheet of paper into the box. Well, that's the equivalent of programming to write a value to a piece of paper

Now that you have a basic idea of ​​what the variables are, we will write to test a small piece of code. But first we will have our first glimpse of the coding window.

To simplify your life , we will put a button on our form . When the button is clicked , a small message box appears. Fortunately there is no coding to write for a button , and very little at all to a message box .

1 comment: