Previous: 119: Automating Tasks with Procedures
The Action menu isn’t the only way code can run. There are many situations where code can run automatically in response to different events, including opening a database, adding or removing a record, or editing data.
Here is a short program designed to run in response to a phone number being edited. Using the formatphone( function, it automatically formats the phone number in the format (999) 999-9999
format. If the area code is missing, it automatically adds a default area code (in this case 714). If the number contains less than 7 digits, it displays a notification.
local digits
digits = striptonum(Phone)
if length(digits) = 0 or length(digits)>10
return
elseif length(digits) = 7
digits = "714"+digits
endif
if length(digits) = 10
Phone = formatphone(digits)
return
endif
if length(digits)<7
nsnotify "Bad Phone Number?","text","Only "+pattern(length(digits),"# digit~")
endif
To run this code in response to a phone number being entered, place this code in the Code section of the Field Properties Panel for the Phone field.
This code will run automatically whenever a phone number is entered into the database (or modified).
Next: 121: Extra Credit: Importing and Cleaning Up More Names
See Also
History
Version | Status | Notes |
10.0 | Updated | Carried over from Panorama 6.0, with updates. |