In some cases the designer needs to limit their text variables to a maximum size. For example, the designer wants to allow the user to enter a company description for their business partner records, but it cannot exceed 255 characters. The designer could easily truncate the variable when saving the record, but it's not very user friendly.
Instead, count down the number of characters that the user can enter, and display it on the form so that they know when they've reached the limit. You can also prevent the user from entering more than the maximum number of characters as well.
Here is what is needed:
1) On the user entry form: The user entry variable such as the description variable or any text variable of restricted length
2) On the user entry form: Numeric variable with name "Count" (under the description variable)
3) On the user entry form: Text object with string "characters left" (directly to the right of the count variable)
4) In Form Method's "On Load" section:
` Form Method
: (Form event=On Load )
EntryVariable:="Initial value from record or elsewhere"
myCount:=MaxEntry-Length(EntryVariable) ` this user entry object must be defined
5) Here is the code to use in your EntryVariable's object method:
` Object Method: EntryVariable
` Description: Check the size of the text entered and limit its size to 255.
` Update the Count variable to show how many characters are left.
: ($formEvent=On After Keystroke ) | ($formEvent=On After Edit )
$length:=Length(Get edited text)
` remove excess characters during entry
Self->:=Substring(Get edited text;1;MaxEntry)