Note that inside the event handler, if the validation fails then I correct the text so there is reentry in the code, which will not modify the text again because of previous correction (there will be no more reentry).
The problem is that the handler is not invoked every two changes. For example
Scenario 1)
-If the user presses SPACE, then handler is invoked and the space is removed).
-If the user presses space again (no matter how long it takes to do so), then the handler is not invoked, so the uncorrected space is displayed.
Scenario 2)
-The user enters three letters, for example, ABC.
-The user enters a fourth letter, then the handler will correct it and the user will still see ABC.
-The user enters another letter again, but this time the handler is not invoked. So the fourth letter is displayed, for example ABCd.
I hope you understand that Power Users could be sleeping or are doing other things. Power Users spend their free time helping in the community. So there is no need to spam the topic, just be patient.
Hi @ABG,
Sorry it took me a while to give feedback, I was running a lot of tests. TextBox does not fire the event after correcting, for instance, 'ABCd' to 'ABC' and then user type letter 'd' again. This text change confuses it by returning to a previous value, i guess.
I have decided to move to TaifunTextBox (as suggested by @HarshVardhanSolanki). I just had to make sure in the event handler that it doesn't fall into recursion until stack overflow. I used a reentry counter, with a value equal to one (first entry) as a condition to be able to modify the text inside the handler.
counter = 0
when TaifunTextbox1.AfterTextChanged
counter = counter + 1
if counter equal 1
if validation fails
set tb.Text to newValue
counter = counter - 1
@Taifun, The pseudo code implementation above works perfectly, the event handler is always invoked.
I'm left with the feeling of not knowing what's going on with the TextBox. Exactly the same code works using TainfunTextbox.
I knew I would only solve this by using the Timer... but I wasn't sure how to implement it... and I was going a completely wrong way, disabling the component, using the timer and activating the component on the way back. .
The initial programming of this topic is a masterpiece to exemplify how block processing works and how the triggers of Events work.
There is no need for you to keep asking people to mark solutions. It will get done. Please stop doing this, it just clutters up the community with unnecessary posts.
For the sake of knowledge (not such a practical approach), here are my personal observations.
TextBox.TextChanged event can be re-entered when TextBox.Text property (the trigger) is changed (pulled) within its code. Care must be taken to avoid throwing a stack overflow.
I'm still unsure if TextBox has any issues. Exactly the same code does its job well within TaifunTextbox.AfterTextChanged event handler. The unanswered question is why does the input sequence 'abcde' triggers the event on the last text change (typing 'e' after auto removing the fourth letter), but 'abcdd' does not.
I kindly thank @ABG again for rolling up his sleeves and work on an alternative solution.
Some software layer is trying to de-bounce the simulated keyboard input (not likely)
There is a race condition exposed by the faster keyboard input speed of holding down a letter versus switching letters. There are essays on the AI2 thread model at FAQ Section: Waiting and Timing but I am not prepared for such a deep dive.