Question: sum of numbers in visual basic create an application that displays a form that when the enter numbers button is clicked, the application should display

sum of numbers in visual basic create an application that displays a form that when the enter numbers button is clicked, the application should display the input box. the input box asks the user to enter a positive integer value. The default input value is 10. when the ok button is clicked, the application should display a message box with the sum of all the integers from 1 through the value entered by the user. if the user enters a negative value, the application should display an error message. use the following test data to determine if the application is calculating properly value sum 5 15 10 55 20 210 100 5050

Public Class Form1

Private Sub btnEntNum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEntNum.Click

Dim sum As Integer 'sum of numbers

Dim n As String 'number

'Get number from the user

n = InputBox("Enter a positive value:", "Input Needed", "10")

For sum = 1 To n

'Calculate the sum of numbers

sum = n * (n + 1) / 2

'Display the result

MessageBox.Show("The sum of numbers from 1 through" & n.ToString() & "is:" & sum.ToString(), "Sum of Numbers")

Next

End Sub

The program works it just won't display the error message when a negitave number is entered.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!