Guys Help Please
I have a textbox that needs to add up values from 3 other textboxes.
I dont want to use the afterchange method on the other 3 textboxes. Is there a way i can assign or run a method that does the calculation throughout runtime.
Like what excel would have done.


Please show us your code work first. (Read member rules).

Edited 5 Years Ago by __avd: n/a

i doont have any code yet for i dont know how to approach it. But currently i am using, eventhandler of the textboxes to add the values. thinking this may be the only way thou.

Are you giving any button upon clicking u want to calculate? or on fly u want to?

if its on the fly, you should give preferences to the text-boxes so that there wont any error in the calculation(by skipping a text-box) or better still, you can just code a button to help do the summation.

In form load assign default values to text box's

TextBox3.Text = 0
            TextBox4.Text = 0
            TextBox5.Text = 0

And in textchanged event

Private Sub TextBox3_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged, TextBox4.TextChanged, TextBox5.TextChanged
    End Sub

Calculate Method:

            Dim One As Integer
            Dim two As Integer
            Dim tree As Integer
            One = Convert.ToInt64(TextBox3.Text)
            two = Convert.ToInt64(TextBox4.Text)
            tree = Convert.ToInt64(TextBox5.Text)
            TextBox6.Text = Math.Round(One + two + tree)
        Catch ex As Exception
        End Try

If you don't want to go with the textchanged events, you can have a timer call the calculate function.

This article has been dead for over six months. Start a new discussion instead.