» Home
» Tutorials
» Search  
» Contact us 

Home » Tutorials » Introduction to Visual Basic .NET » Chapter 3

3.6: Data Types
3.6.1: Numbers
3.6.1.2: Common Integer Math Operations

Common Integer Math Operations

In this section, you create a new project for your math operations.

 

Exercise - Common Integer Math

1. Create a new project in Visual Studio 2005 by selecting File * New * Project from the menu. In the New Project dialog box, select Windows Application from the right pane, and enter the project name as IntegerMath and click OK.

2. Using the Toolbox, add a new Button control to Form1 as before. Set its Name property to btnIntMath and its Text property to Math Test. Double-click it and add the following highlighted code to the new Click event handler that will be created:

Private Sub btnIntMath_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnIntMath.Click
‘Declare variable
Dim intNumber As Integer

‘Set number, add numbers, and display results
intNumber = 16
intNumber = intNumber + 8
MessageBox.Show(“Addition test... ” & intNumber, “Integer Math”)

‘Set number, subtract numbers, and display results
intNumber = 24
intNumber = intNumber - 2
MessageBox.Show(“Subtraction test... ” & intNumber, “Integer Math”)

‘Set number, multiply numbers, and display results
intNumber = 6
intNumber = intNumber * 10
MessageBox.Show(“Multiplication test... ” & intNumber, “Integer Math”)

‘Set number, divide numbers, and display results
intNumber = 12
intNumber = intNumber / 6
MessageBox.Show(“Division test... ” & intNumber, “Integer Math”)
End Sub

3. Run the project and click the Math Test button. You’ll be able to click through four message box dialog boxes, as shown:

 

click next Page - How It Works.

Home | Link to Us | Partner Links | About us | Contact us

Copyright © 2009-2012 F1tutorials.com | All Rights Reserved