Hi,

I want to add a button (ButtonCalculate) to make the user select this button to generate the loop for calculating the sum.

Private Sub TextBox1Integer_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1Integer.TextChanged
        
      Dim OddSum As Integer = 0 
        Try
            Dim CountTo As Integer = TextBox1Integer.Text
            For Index As Integer = 1 To CountTo
                If Index Mod 2 <> 0 Then
                    OddSum += Index
                End If
            Next
            Label1Output.Text = "Sum is: " & OddSum.ToString
        Catch ex As Exception
            MessageBox.Show("Error - Please Enter An Integer")
        End Try
    End Sub

Recommended Answers

All 2 Replies

add a button to your form and copy the code you have above to the click event.

Thank you.

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.