The user enters an integer into a text box and clicks on the Calculate button. The application will sum all of the integers from 1 to the number entered and display the sum in a label. The sum of numbers is the sum of all the numbers from 1 to the ending number. For example, if the user enters 3, the sum of numbers is 1 + 2 + 3 = 6. If the user enters 5, the sum of numbers is 1 + 2 + 3 + 4 + 5 = 15. Your program should work for any integer entered by the user.
The user enters an integer into a text box and clicks on the Calculate button. The application will sum all of the integers from 1 to the number entered and display the sum in a label.
The sum of numbers is the sum of all the numbers from 1 to the ending number. For example, if the user enters 3, the sum of numbers is 1 + 2 + 3 = 6. If the user enters 5, the sum of numbers is 1 + 2 + 3 + 4 + 5 = 15. Your program should work for any integer entered by the user.
Use a loop to calculate the sum of numbers. You will need to initialize the variables and assign appropriate values. Get the value for intEndNum from the textbox. After the loop has run, display intSum in the label.
Here is one way to code the loop:
For intCount = 1 To intEndNum
intSum = intSum + intCount
Next
Calculate Button Click-Event Procedure
You may find following these steps helpful:
- Declare three variables
intEndnum Ending number provided by the user intCount Loop counter intSum Running total - Get the ending number from the user. Assign the text property of your textbox to intEndNum
- Code the loop. A sample is given above.
- Display the running total. Assign intSum to the text property of your label.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 4 images