# please help me with this program. in desperate need of the code

• ### Question

• Create a VB application that calculates the cumulative sum for a range of values specified by the user.

Cumulative Sum Example:

Given a range of numbers : 1 2 3 4 5

Cumulative Sum Sequence : 1 1+2 1+2+3 1+2+3+4 1+2+3+4+5

Output 1 3 6 10 15 5.

The application should

1. Allow the user to enter the lower limit and upper limit for a range of numbers.

2. When the button “Cumulative Sum” is clicked, using a FOR loop, calculate and display the cumulative sum sequence in a list box as shown in the sample output below.

3. Use class variables and type casting wherever necessary.

4. Choose an appropriate data type for the class variables.

5. Set Option Strict to ON.

6. The output (cumulative sum) must be displayed in a list box on the form.

Friday, April 13, 2018 5:42 AM

### All replies

• Friday, April 13, 2018 7:46 AM
• We don't help with code for school assignments.

However, with the information on this page it should easy to do.

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

Success
Cor

Friday, April 13, 2018 9:21 AM
• If you spent as much time reading your programming book as you do posting on forums you would be done by now.

Friday, April 13, 2018 10:48 AM
• Which part are you stuck on? You don't display any code so who but you knows which parts you have done so far.

I would suspect the instructor has already provided the necessary instruction for what you have to do. Therefore which part are you having difficulty with? Dragging a ListBox onto the Form?

La vida loca

Friday, April 13, 2018 4:27 PM
• Hi aboulelaa,

Firstly, you want to limit the number the user enter, but I don't know where user enter the number, here is the limit the number,

``` Dim num As Integer = 121
If num > 100 OrElse num < 1 Then
MessageBox.Show(" the number out of range!")
End If```

If you want to display these cumulative sum sequence in listbox, you can take a look the following code:

```  Private Sub Frmsum_Load(sender As Object, e As EventArgs) Handles MyBase.Load
TextBox1.Text = "1 2 3 4 5"
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim arr() As String = TextBox1.Text.Split(" ")
Dim sum As Integer
For i As Integer = 0 To arr.Length - 1
sum += arr(i)

Next
End Sub```

You can modify the code according to your situation to achieve your goals.

Best Regards,

Cherry

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

• Proposed as answer by Tuesday, April 17, 2018 9:26 AM
Monday, April 16, 2018 2:48 AM