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
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.
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.
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
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)
Calculate the sum of the numbers.
result = firstNum + secondNum + thirdNum
Display the calculated result.
Press "F5" to run the program and enter a number in each of the text boxes. Click "Button1."
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for