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:
B4X:
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
 

Erel

Administrator
Staff member
Licensed 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:
B4X:
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
 
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 :)
 

Attachments

klaus

Expert
Licensed User
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.
 
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. :)
 

Attachments

Last edited:

klaus

Expert
Licensed 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 !
 
Top