Android Question EditText_TextChanged help

Greetings to all!
It's my first time posting here so please bear with me..

I'm creating a program where in a form, it contains 4 EditText and the 5th Edit Text is for the result.
What I want to happen is while the user is inputting the values the 5th EditText will automatically shows the result. In Visual Studio 2013 the code is like:
Public Sub TextBox5_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged, TextBox2.TextChanged, TextBox3.TextChanged, TextBox4.TextChanged
  Dim x As Integer
  x = (Val(TextBox1.Text) + Val(TextBox2.Text) + Val(TextBox3.Text) + Val(TextBox4.Text))
  TextBox5.Text = x
  End Sub


B4X founder
Staff member
Licensed User
Longtime User
Set the EventName property of all the EditTexts to the same value (for example et).
There is no Val keyword in B4A as the compiler converts the string to number automatically. However in this case you want to check that the string is a valid number:
Sub et_TextChanged (Old As String, New As String)
   Dim x As Int = Val(EditText1.Text) + ...
   EditText5.Text = x
End Sub

Sub Val(s As String) As Double
   If IsNumber(s) Then Return s
   Return 0
End Sub
Upvote 0
Thank you for replying, I tried this code but it has an error that wants to force close the app when I start to input, here's my code.. thanks for your future help :)


    7.1 KB · Views: 232
Upvote 0
You must set a different EventName for EditText5.
In your case you enter in an infinite loop because when you change EditText5.Text the the event is raised.

EditText5 already has a different Event Name from the other,
Here's the screen shot of where the error takes place, I might be missing something here, I'm sorry and thanks for all your help. :)


  • dasdfsadf.jpg
    137.2 KB · Views: 257
Last edited:
Upvote 0


Licensed User
Longtime User
In the project you posted in post#3 the event name for EditText5 is the SAME as for the 4 others !
I tested it before posting my answer !
The code in post#3 (Erels' proposal from post#2) and the code you show in post#6 is NOT the same !
Test your project from post#3 after having changed the event name for EditText5, it works !
Upvote 0