B4J Question Change characters in TextArea

johan vetsuypens

Member
Licensed User
Hi,

I'm using the TextArea to enter multi-line text. I want to automatically replace characters in the inputted text.
As an example, I want to change the 'enter' character chr(13) with the text string "<CR>"

I can't use the TextChanged event below, because the application will loop forever. Also , the TextArea does not have an 'Action' event. TextField is not allowing multi-lines. How can I solve this ?

Sub TextAreaInput_TextChanged (Old As String, New As String)

TextAreaInput.Text = TextAreaInput.Text.Replace (Chr(13) , "<CR>")

End Sub



thanks,
Johan
 

Ed Brown

Active Member
Licensed User
You can use a flag to indicate that text has been changed to stop the infinite loop. Set the flag when text has been changed, change what you need and clear the flag. At the start of the sub check if the flag is set and if it is then return and do nothing...something like this...
B4X:
Sub Globals
    Private IsUpdatingText As Boolean = False
End Sub

Sub MyTextEdit_TextChanged (Old As String, New As String)
    If IsUpdatingText = True Then Return
    IsUpdatingText = True
   
    ' Do your code magic here
    ...
    ' Don't forget to reset the flag at the end of your code
    IsUpdatingText = False
End Sub
 
Upvote 0

johan vetsuypens

Member
Licensed User
You can use a flag to indicate that text has been changed to stop the infinite loop. Set the flag when text has been changed, change what you need and clear the flag. At the start of the sub check if the flag is set and if it is then return and do nothing...something like this...
B4X:
Sub Globals
    Private IsUpdatingText As Boolean = False
End Sub

Sub MyTextEdit_TextChanged (Old As String, New As String)
    If IsUpdatingText = True Then Return
    IsUpdatingText = True
  
    ' Do your code magic here
    ...
    ' Don't forget to reset the flag at the end of your code
    IsUpdatingText = False
End Sub
Hi Ed,

I tried this, but this didn't work, because the place where the 'do your magic code here was containing the command : MyTextEdit.Text = MyTextEdit.Text.Replace (Chr(13) , "<CR>")

This line of code was only executed after the sub was exited.

Note : reflector does the job.

thanks,

Johan
 
Upvote 0
Top