Tuesday, January 20, 2009

Visual Studio2008: Explaination of Variable Woking

The program starts at the top and works its way down, one line at a time, to the bottom. The first line defines a new variable, called intNumber :

Dim intNumber As Integer

Dim is a keyword.A keyword has a special meaning in Visual Basic 2008 and is
used for things such as commands. Dim tells Visual Basic 2008 that what follows is a variable
definition.
As Integer tells Visual Basic 2008 what kind of value you want to store in the variable. This is
known as the data type . For now, all you need to know is that this is used to tell Visual Basic 2008 that you expect to store an integer (whole number) value in the variable.
The next line sets the value of intNumber :

intNumber = 27

In other words, it stores the value 27 in the variable intNumber .

The next statement simply adds 1 to the variable intNumber :

intNumber = intNumber + 1

What this line actually means is: Keep the current value of intNumber and add 1 to it.

The final line displays a message box with the text Value of intNumber + 1 = and the current
value of intNumber . You ’ ve also set the title of the message box to Variables to match the project name. When using numeric variables in text, it is a good idea to use the ToString method to cast the numeric value to a string. This prevents the compiler from having to figure out that this is a number and then converting that number to a string so it can be displayed:

MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString, _
"Variables")






No comments:

Post a Comment