Welcome to Dream.In.Code
Become a VB Expert!

Join 137,234 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,708 people online right now. Registration is fast and FREE... Join Now!




Sum of Numbers

 
Reply to this topicStart new topic

Sum of Numbers, Need third messagebox to display info

VBisKillingMe
16 Mar, 2007 - 09:13 AM
Post #1

New D.I.C Head
*

Joined: 8 Mar, 2007
Posts: 11


My Contributions
CODE
Dim strUserInput
        Dim IntUserInput As Integer
        Dim i As Integer
        strUserInput = InputBox("Enter a positive integer value", "Input Needed", 10)
        If strUserInput <> String.Empty Then
            Try
                intUserInput = CInt(strUserInput)
                If IntUserInput < 0 Then
                    MessageBox.Show("Negative numbers are not accepted.")
                End If
            Catch ex As Exception
                MessageBox.Show("Quantity amount must be numeric.")
            End Try
            'Show messagebox,
        Else
            'IntUserInput = (IntUserInput + i)
            InputBox(MessageBox.Show("Sum of Numbers", "The sum of numbers" & (i + IntUserInput), MessageBoxButtons.OK))
        End If

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sum Of Numbers
16 Mar, 2007 - 09:55 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
CODE

InputBox(MessageBox.Show("Sum of Numbers", "The sum of numbers" & (i + IntUserInput), MessageBoxButtons.OK))

Remove InputBox from around the MessageBox.Show.
CODE

MessageBox.Show("Sum of Numbers", "The sum of numbers" & (i + IntUserInput), MessageBoxButtons.OK)

User is online!Profile CardPM
+Quote Post

VBisKillingMe
RE: Sum Of Numbers
16 Mar, 2007 - 11:02 AM
Post #3

New D.I.C Head
*

Joined: 8 Mar, 2007
Posts: 11


My Contributions
I removed the Input box... I had added that to see if it would help make the Messagebox appear, but it didn't


It's supposed to look like this... application called Sum of Numberfs has two buttons on it... Enter Numbers and Exit. When you click Enter Numbers you get an Inputbox box where a user can enter any positive integer. The default number displays as 10. That part works. The input box is has two buttons OK and Cancel. When you click the OK button you're supposed to a Messagebox(?) that totals every positive integer from 1 to the number that user has input and gives a total. For example, if the input is 10 then the Messagebox displays "The sum of numbers 1 through 10 is 55.

Any ideas?
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sum Of Numbers
16 Mar, 2007 - 12:09 PM
Post #4

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,985



Thanked: 44 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
That is because the only way the code for that MessageBox will ever execute is if the strUserInput is empty. You currently have it in the Else portion of an IF statement. So only one or the other set of statements will execute depending on the resulting condition of the IF statement.

I think what you mean to do is this:
CODE

Dim strUserInput
        Dim IntUserInput As Integer
        Dim i As Integer
        strUserInput = InputBox("Enter a positive integer value", "Input Needed", 10)
        If strUserInput <> String.Empty Then
            Try
                intUserInput = CInt(strUserInput)
                If IntUserInput < 0 Then
                    MessageBox.Show("Negative numbers are not accepted.")
                    Exit Sub
                End If

            'IntUserInput = (IntUserInput + i)
            MessageBox.Show("Sum of Numbers", "The sum of numbers" & (i + IntUserInput), MessageBoxButtons.OK)

            Catch ex As Exception
                MessageBox.Show("Quantity amount must be numeric.")
            End Try
            'Show messagebox,
        Else
            MessageBox.Show("Incorrect input", "You must enter a positive integer value", MessageBoxButtons.OK)
            Exit Sub
        End If


You are still missing one important element in order for you to correctly sum up the numbers. You will need a loop to go through all the numbers adding them up as it goes along keeping a running total.
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/4/08 03:51PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month