Hello,
I have a program that I've created a Do While loop counting to 100 in 5s. I get the results perfectly, but now I am trying to add the sum of all the numbers in the box and display in a label. I get the number 100 in the label - but that's not the sum of all the numbers in the textbox. The code is what I have below:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number As Integer
number = -5
Do While number <= 95
number = number + 5
ListBox1.Items.Add(number)
Loop
For Each sumTotal As String In ListBox1.Items
Label1.Text = sumTotal
Next
End Sub
End Class
Any suggestions on how to fix the sum/label issue?
Thanks!
I have a program that I've created a Do While loop counting to 100 in 5s. I get the results perfectly, but now I am trying to add the sum of all the numbers in the box and display in a label. I get the number 100 in the label - but that's not the sum of all the numbers in the textbox. The code is what I have below:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number As Integer
number = -5
Do While number <= 95
number = number + 5
ListBox1.Items.Add(number)
Loop
For Each sumTotal As String In ListBox1.Items
Label1.Text = sumTotal
Next
End Sub
End Class
Any suggestions on how to fix the sum/label issue?
Thanks!