How to Calculate the Sum of 3 Numbers in Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Calculate the Sum of 3 Numbers in Visual Basic
Add numbers using Visual Basic. (Jupiterimages/Comstock/Getty Images)

Calculating the sum of three numbers can easily be accomplished using a Windows Forms Project in Visual Basic. The best thing to do is to let the user enter the three numbers using text boxes then you can get the values programmatically. In VB, you can use the "+" operator to add numbers and save the result to a variable. The operator can be used to add two or more numbers.

Skill level:
Moderately Easy

Other People Are Reading

Instructions

  1. 1

    Launch Microsoft Visual Basic Express and click "New Project" on the left pane of your computer screen. Click "Visual Basic" below Installed Templates, then click "Windows Forms Application," and then click "OK" to start a new project.

  2. 2

    Double-click the "TextBox" control on the "Toolbox" pane to add one to your form. Add two more text boxes and a "Button" using the same technique.

  3. 3

    Double-click the button to create a button click event. Add the following code to create your variables:

    Dim firstNum As Integer

        Dim secondNum As Integer
    
        Dim thirdNum As Integer
    
        Dim result As Integer
    
  4. 4

    Get the numbers entered in the text boxes.

        firstNum = Convert.ToInt32(Me.TextBox1.Text)
    
        secondNum = Convert.ToInt32(Me.TextBox2.Text)
    
        thirdNum = Convert.ToInt32(Me.TextBox3.Text)
    
  5. 5

    Calculate the sum of the numbers.

        result = firstNum + secondNum + thirdNum
    
  6. 6

    Display the calculated result.

        MessageBox.Show(result)
    
  7. 7

    Press "F5" to run the program and enter a number in each of the text boxes. Click "Button1."

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.