954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Add Button To Generate A Loop

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
Alex_2011
Light Poster
34 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

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

ChrisPadgham
Posting Pro in Training
413 posts since Sep 2009
Reputation Points: 102
Solved Threads: 78
 

Thank you.

Alex_2011
Light Poster
34 posts since Jan 2012
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: