Database Solutions - Hints & Tips

Tip 09:
Intercepting Input Character by Character

Problem

When data is entered into a field the first character will cause the "start modification trigger" to be fired, from this point on no other triggers will be fired until another operation is performed e.g. leaving the field. It may be useful on certain occasions to actually intercept the data being input character by character, by doing so this will allow the contents of the field to be known each time a character is input.

Solution

By making use of the UNIFACE ‘MACRO’ command this can be achieved as outlined below.In the field requiring character by character input checking (FIELD1) the start mod trigger requires the following macro statement:

MACRO "^NEXT^FIELD^PREV^FIELD^LAST_TEXT"

This will cause control to be passed to the next field (FIELD2) and then back to the input field and will position the cursor immediately after the last character entered. When further characters are entered the start mod trigger will again be fired, this will continue until the leave field trigger is activated.

Example of usage

Consider an application holding all driving licence numbers currently held in the UK.

Using current methods of retrieval we could use a standard picklist screen which would retrieve and display driving license numbers matching the users input profile allowing one to be selected and returned to the calling screen. A conventional Dropdown list would be functional but in this case would not be practical, the volume of data to be displayed would make it an inefficient method for a user to find the relevant item.

By using the character by character input method described above and a listbox in connection with the entry field (FIELD1) and the additional field (FIELD2) the list could be dynamically changed as each character of the field is entered, thus giving the user immediate feedback.

Another example is in standard Microsoft Windows Help Topics, where the first few letters restrict the search.

Method

The macro statement in "start mod" of FIELD1 will be required as above.

The "previous field" trigger of FIELD2 will be fired when each character is entered (caused by the macro "^next^field command) and by including the following code will allow a list to be built matching the current contents of the input field.

<PREVIOUS FIELD> (FIELD2)

clear/e "licenses" clear data

uppercase FIELD1, $1 convert field to upper ,save in $1

Lic_no.Licenses = "%%$1%%%" profile field

retrieve/e "Licenses" retrieve data

putlistitems/id $valrep(matches), Lic_no.Licenses, Lic_no.Licenses populate field matches with hits

(matches) is a listbox widget

This will cause the list box (matches) to dynamically change each time a character is entered by inserting the code "FIELD1 = matches" in the value changed trigger of the "matches" field the user can select an item from the list box to be the entry required in FIELD1.

compuware_01.gif (3977 bytes)


Copyright ©2000 OCS Consulting plc

dbs_block_logo.gif (2150 bytes)
Refresh Frames