[SOLVED] character count at runtime

Author: fearandir@gmail.com (fearandir)

Hi all Currently  we are developing a SMS messaging tool. We need a "character counter" solution which count the remaining characters until reach 160. Must be at run time, while user is writing.   I founded this beauty, but we are under Uniface 9.4.  Some workaround?   Uniface 9.6.0.4 (Service Pack MX03) + The Edit Box widget now supports incremental searching by means of an onEdit extended trigger that can be used to respond to user input as the user enters data.   Thanks, Sergio

4 Comments

  1. Hi Sergio, This is not really pretty, but it should work:

    1. In the Start Modification Trigger of the field where the user enters the SMS text set a component variable to true (e.g. $SMOD$="T"), calculate the remaining characters (e.g. vRemainingChars = 160 - $length(@$fieldname)) and execute the macro "^NEXT_FIELD" 2. In the <Next Field> trigger check if the variable (e.g. $SMOD$) has been set; if that's then reset the variable to false ($SMOD$="F") and issue a return(-1)

    Instead of doing the calculation in the Start Modification Trigger you also could do it in the <Next Field> trigger (right before the return(-1)). Please note that Uniface will think that the user tries to leave the current field when the macro "^NEXT_FIELD" is executed. So please be "careful" with the code that is executed in the Validation and Leave Field Trigger - maybe you should put the code in the mentioned triggers in an if-clause that is only executed when $SMOD$="F". Just an idea. Hope this helps - and I hope that I did not forget something. Confused Kind regards, Daniel


    Author: diseli (daniel.iseli@uniface.com)
  2. Thank you Daniel. It works. I hate triggers logic sometimes Kiss   Sergio.


    Author: fearandir (fearandir@gmail.com)
  3. Hi Sergio, You are welcome. And glad to hear that it works. CoolThe "wonders" of (the) Uni-verse. Wink Daniel


    Author: diseli (daniel.iseli@uniface.com)
  4. diseli said

    1. In the Start Modification Trigger of the field where the user enters the SMS text set a component variable to true (e.g. $SMOD$="T"), calculate the remaining characters (e.g. vRemainingChars = 160 - $length(@$fieldname)) and execute the macro "^NEXT_FIELD"
    • OK, we are back in the old SMOD-NFLD ping-pong.
    • Please have in mind that the SMOD is activated BEFORE the entered key is processed. So you see the field contents as it is before one modified it. As a consequence, your length estimation inside of the SMOD may not be correct.

    Author: ulrich-merkel (ulrichmerkel@web.de)