Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

What am i doing wrong??

Option Strict On

Public Class Form1

Dim blnOk As Boolean = True

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

Close()

End Sub

Private Sub btnNums_Click(sender As Object, e As EventArgs) Handles btnNums.Click

Dim dblInput As Double

Dim dblSum As Double

Try

Validation(dblInput)

If blnOk = True Then

dblSum = Calculate(dblInput)

Display(dblSum.ToString)

End If

Catch ex As Exception

End Try

End Sub

Private Sub Validation(ByRef Inputs As Double)

Dim strInput As String = InputBox(

"Enter a positive Number value", "input needed", "10")

If CInt(strInput) < 0 Then

MessageBox.Show("Enter positive numbers ", "invalid input")

blnOk = False

Exit Sub

End If

End Sub

Private Function Calculate(ByVal Sum As Double) As Double

'declares value for user input

Dim intInputNumber As Integer

'stores the sum of numbers

Dim intsum As Integer = 0

'Dim strInput As String = InputBox(

'"Enter a positive Number value", "input needed", "10")

'loops for sum

'1 thru the valued entered

Dim intCounter As Integer

For intCounter = 1 To intInputNumber

intsum += intCounter

Next

MessageBox.Show("The sum of numbers 1 through " &

intCounter & " is " &

intsum.ToString("d"), "sum of numbers")

Return intInputNumber

End Function

Private Sub Display(ByVal Calculate As String)

Calculate = Calculate

End Sub

End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago