Android Question EditText_TextChanged help

Discussion in 'Android Questions' started by Grace Estoperez, Jan 28, 2015.

  1. 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:
    Code:
    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
     
  2. Erel

    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:
    Code:
    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 StringAs Double
       
    If IsNumber(s) Then Return s
       
    Return 0
    End Sub
     
  3. 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 :)
     

    Attached Files:

    • g.zip
      File size:
      7.1 KB
      Views:
      55
  4. Erel

    Erel Administrator Staff Member Licensed User

    Please post the error message from the logs (right click to copy).
     
  5. klaus

    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.
     
    Erel likes this.
  6. 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. :)
     

    Attached Files:

    Last edited: Jan 30, 2015
  7. here's the log, thanks
    log.jpg
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    Please read my previous answer in post #2. Your code is wrong.
     
  9. klaus

    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 !
     
  10. Oh my I'm so sorry..
    Thanks for pointing me on my mistakes, now it's working because of your help Klaus and Erel. Thank you so much!!! :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice