Tuesday, January 20, 2009

Visual Studio2008:Variables And Its Working

A variable is something that you store a value in as you work through your project. You can then
make a decision based on that value (for example, “ Is it equal to 7? ” or “ Is it more than 4? ” ), or you can perform operations on that value to change it into something else (for example, “ Add 2 to the value ” , “ Multiply it by 6 ” , and so on).

1. Create a new project in Visual Studio 2008 by selecting File New Project from the menu bar.
In the New Project dialog box, select Windows Forms Application from the right - hand pane
and enter the project name as Variables and click OK (see Figure 21).





2. Make Form1 a little smaller and add a Button control from the Toolbox to it. Set the button ’ s
Text property to Add 1 to intNumber and its Name property to btnAdd. Your form should
look similar Figure 22 .



3. Double - click the button to open the btnAdd_Click event handler. Add the following
highlighted code to it:

Private Sub btnAdd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAdd.Click
Dim intNumber As Integer intNumber = 27 intNumber = intNumber + 1 MessageBox.Show("Value of intNumber + 1 = " & intNumber.ToString, _ “Variables”)
End Sub

4. Click the Save All button on the toolbar, verify the information in the Save Project dialog box,
and then click the Save button to save your project.

5. Run the project, click the Add 1 to intNumber button, and you ’ ll see a message box like the
one in Figure 23 .



No comments:

Post a Comment