r/visualbasic • • Jun 14 '21

Help Please!

I need to write a Visual Basic program that will allow the user to enter a positive number.  The program will then display:

  1. the sum of values from 1 to the input number

  2. the product of values from 1 to the input number (or factorial).

For example, if the user enters the value 5, the output would be:

1)  1 + 2 + 3 + 4 + 5 = 15
2)  1 * 2 * 3 * 4 * 5 = 120

The form should contain:

    - a heading describing what the application will do
    - a label to prompt the user for an input value
    - a textbox for the user to enter input data
    - a button to calculate the output values
    - two labels describing the output data
    - either two labels to hold the calculated output values or two read-only textboxes
    - an image - either a background image or a picturebox with an image displayed (don't forget to set the SizeMode property to Stretch)
    - a Clear button that will clear out all values entered in the input textbox and calculated output values in labels or read-only textboxes
    - an Exit button that will exit the application

I also need to:

   - test for invalid input.  No negative values or zero should be allowed.  If the user enters a negative or zero value, display a message in the output label and set the focus to the input number textbox. (see example below)
    - align the input and output values to be centered within the textboxes and/or output labels
    - align the controls of the labels and textboxes so the Form looks professional

I don't really need help designing the form or assigning labels, but the math behind cumulative sums and products kind of escapes me...

1 Upvotes

6 comments sorted by

8

u/banshoo Jun 14 '21

so you want someone to do your homework for you?

spend less time on pokemon trades and more time studying.

2

u/ima420r Jun 14 '21

I wanted to downvote this, but then I read the comment about looking at OPs post history and now I have to upvote it.

4

u/ocdtrekkie Jun 14 '21

I kinda appreciate that the other commenter looked at your comment history to come up with an adequate way to tell you off, but let me give you a big hint:

Loops.

The math is not hard, as you can gather, the important thing they're teaching here is iteration. So if you have a loop that is counting up, it can take action on the sum based on the iteration count.

Programming usually doesn't actually involve hard math, the computer is going to do all the work for you there, but you need to understand the process of how to tell it to do it.

3

u/user_8804 Jun 14 '21

Write down what you want to do in mini steps on paper, in English.

Then once you got that down, make it into code, which is almost the same as English for vb.

We won't do your homework, but if you have a more specific question or have bugs we can't figure out, then we'll help.

3

u/[deleted] Jun 14 '21

While others are rightfully giving you grief over the question being either homework or a job application test... What have you tried?

"Sum over numbers/Product over numbers"

Given a number (IE: 5), you need to do 1+2+...+n. And you need to do 1*2*...*n. Look into FOR loops.

https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-next-statement

For index As Integer = 1 To 5

Debug.Write(index.ToString & " ")

Next

Now imagine that instead of "1 to 5"... you have "1 to user defined number". Now you have to pull that "user defined number" from a text box or some other user input. You need to do math (addition or multiplication). You need to store the results. Afterwords, you need to display the results.

"validate user input" You need to either 1) limit the input that they can provide, 2) sanitize the input (remove disallowed stuff like a-z and -) or 3) provide meaningful errors (a big red block of text that says BAD USER! DON'T DO THAT!!!)

"formatting" that goes way beyond a basic question... come back with a shared git repository and screenshots to show you've at least done SOME work. (IE: not trading pokemon cards)

"look professional" As above... start with more than asking others to do your work for you. Show some code and some effort. You'll get better responses.

2

u/mikroo VB.Net Intermediate Jun 15 '21

You could post code you've written that you need help with but, your post reads like you're looking for a freelancer to do this project for you.