In a Unifield, return the Uniface character code for the key that activated a trigger.


Return Values

  • Code for the character or function chosen by the user which activated a trigger.
  • In the userKey trigger, $char contains the ^USER_KEY identifier character code.


Use in Form components, but only applicable to Unifields.


In a Unifield, the function $char returns the last Uniface character or function (in decimal format) which activated a trigger. It is most commonly used with the startModification and userKey triggers, but can be used with all triggers.

Note:  The function $char is available only in Unifields. Its value in other widgets cannot be predicted.

Using $char

In the following example, ProcScript in the startModification trigger checks $char to see if the user entered the letter 'Y' into the field. If that was the modification, the ProcScript module ends and the user can continue. If the user entered any other letter, the code sets $status to -1, causing the modification to be discarded.

trigger startModification
if (($char = 89) | ($char = 121))
  message "This field may only be set to ’Y’!"
  return (-1)
edn; startModification

The kind of value checking shown in the previous example can also be achieved by using a declarative entry format for the field, for example, ENT(y) . However, entry formats are only checked when the user leaves the field. The startModification trigger is activated the moment the user enters data. ProcScript in this trigger can only check the first character the user has entered, so it cannot be used to enforce an entry format of ENT((yes)(no)).

The following example puts the editor into Zoom mode and inserts a salutation when the user enters a capital D ($char="D" ):

trigger startModification
  string vHonorific
if ($char = 68) ; "D"
  if (GENDER = "M")
   vHonorific = "Mr."
   vHonorific = "Ms."
  macro "^127^096ear %%$1 %%SURNAME, ^CURSOR_RIGHT"
end ; startModification

Related Topics