So hopefully I am aloud to post this here. I am doing great in class but this chapter and especially this programming challenge has got me stumped. So I am in need of help.

Heres the question:
Create an application that when a user enters a positive integer value in a input box(the default number is 10) when the OK button is clicked, the application should display a message box with the sum of all the integers form 1 through the value entered by the user. If the user enters a negative value, the application should display an error message.

I believe i have to use a loop condition but i have no idea what to do.

EX: User enters 10 in the input box once OK button is pressed a message box pops up and says "The sum of the numbers 1 through 10 is 55"

use the following test data to determine if the application is calculating properly
VALUE SUM
5 15
10 55
20 210
100 5050

So i cant seem to find the edit button... so ill just reply to this I figured out some of it and here is the code but i need help polishing it because it does not look like what it is supposed to i will also post pic's of the figures

``````Public Class Form1

Private Sub btnNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumbers.Click

Dim intNumber As Integer 'number entered by user
Dim intCounter As Integer '
Dim intSum As Integer 'sum of numbers

intNumber = InputBox("Enter a positive integer value", "Input Needed", 10)

For intCounter = 1 To intNumber
intSum += intCounter
MsgBox("The sum is" & intSum) it should look like this http://img31.imageshack.us/i/sam0124.jpg/

Next
End Sub
End Class``````

i get a 404 file error why i click on link

Fibonacci anyone?

Fibonacci anyone?

you are on the right track with this code, here are some corrections:

``````Public Class Form1

Private Sub btnNumbers_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNumbers.Click

Dim intNumber As Integer 'number entered by user
Dim intCounter As Integer '
Dim intSum As Integer 'sum of numbers   - I would set this = to 0 right now

intNumber = InputBox("Enter a positive integer value", "Input Needed", 10) 'I've never used InputBox, so i'll assume this is correct.

For intCounter = 1 To intNumber
intSum += intCounter
MsgBox("The sum is" & intSum) 'MOVE THIS out of the for loop!
Next
End Sub
End Class``````

You should also include some code to check that the number entered is positive.
Normally we'd verify if its positive in a loop, but the challenge doesn't seam to want that.

``````intNumber = InputBox("Enter a positive integer value", "Input Needed", 10) 'I've never used InputBox, so i'll assume this is correct.
If intNumber < 0 Then
messagebox.show("Error, You have entered a negative number!")
End If``````

And that should do it.

@Phenneger, please start another thread and post the code you have, I'd be more than happy to help as I've done the Fibonacci sequence many times for projecteuler

Thank you PatPlays852, now go and read the rules.

Do not post homework problems expecting a quick answer without showing any effort yourself. This especially pertains to the software development forums.

Thank you PatPlays852, now go and read the rules.

I don't wish to get in an argument with you, but he did post the code he had. Does this not show that he at least put in an effort?

The only real code that i "gave" him was the if statement, and he'll need to adjust that to fit his purposes, all I did in that other code was add in comments...

I'm sorry but I don't see how I'm wrong here....

T

Thanks for everyones help. As pat stated I did put forth effort as i did most of the code. They lost a portion of the database so i had to make a new account. So if someone could mark this as solve please do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.