Hello...

I have three textboxes on a form.

The first two are for entering numbers for addition.
And the third is for displaying the result of addition.

I want the result of addition to appear in the third textbox as soon as I enter
the numbers in the first two textboxes, without pressing any buttons.

Does anyone know how to do this?

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged

        If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then Exit Sub
        If Not IsNumeric(TextBox1.Text) OrElse Not IsNumeric(TextBox2.Text) Then Exit Sub

        TextBox3.Text = CDbl(TextBox1.Text) + CDbl(TextBox2.Text)

    End Sub

The above code calculates the result, but the result doesn't
appear instantly in the third textbox.

It only appears when I click the third textbox and press any key on the keyboard.

Is there a code that can make the result appear instantly in the third textbox,
as soon as you fill in the first two textboxes?

Maybe some code for simulating a key press or a button click?

The above code calculates the result and shows it instantly in the third textbox.

Copy it and paste it again and name your textboxes Textbox1,Textbox2, and Textbox3.

Type in Textbox1 and Textbox2. Textbox3 will show the result instantly.

i know this post has been resolved but where should i paste the code? in texbox1? textbox2? or textbox3? thanx! for helping me

Edited 3 Years Ago by EXTRA_RICE: wrong grammar

Just add this to your program:

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
    If String.IsNullOrEmpty(TextBox1.Text) OrElse String.IsNullOrEmpty(TextBox2.Text) Then Exit Sub
    If Not IsNumeric(TextBox1.Text) OrElse Not IsNumeric(TextBox2.Text) Then Exit Sub
    TextBox3.Text = CDbl(TextBox1.Text) + CDbl(TextBox2.Text)
End Sub

Because this is handling both textbox1 and textbox2

This code works for me but when i delete both value of the textbox the total is still there... any solution for my problem?

BY a simple TextChange event you could do it

Private Sub TextBox_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged
        Dim x As Double = 0
        For Each actTxtBox As TextBox In Me.Controls
            If (actTxtBox.Name = "TextBox1") Or (actTxtBox.Name = "TextBox2") Then
                x += Val(actTxtBox.Text)
            End If
        Next

        IIf(x > 0, TextBox3.Text = x, TextBox3.Text = "")
    End Sub
This question has already been answered. Start a new discussion instead.