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.

Recommended Answers

All 7 Replies

Welcome.

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

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?

on the fly

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
        Calculate()
    End Sub

Calculate Method:

Try
            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
            MsgBox(ex.ToString)
        End Try

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

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.