With this code in place, Panorama checks values entered into the A field.
Each field can have its own code.
If multiple fields share a significant amount of code, you can set up a named procedure (see Procedures) with the shared code and use the call statement to call it. For example, I could set up a procedure called checkFieldLimits to validate entered data against defined limits.
Notice that instead of using specific field names (A, B, C, etc.) this procedure uses
«» symbol can be used in any formula to access the value of the current field. Use of the
«» symbol allows this procedure to work with any field without modification.
Now that this procedure is set up, we can call it from the code for each field.
This same subroutine can also be called from fields B, C and D, only changing the limits passed as parameters as necessary. Then if you ever need to modify the limit checking code, you only have to make that change in one place, not over and over again for each field. For example, the message statement could be changed to nsnotify. With this change, any entry of an out-of-range value will cause a notification instead of an alert that has to be dismissed.
In this example the code in the field has been completely replaced by a single call statement, but that’s not necessary. You can mix in whatever code you want into the field’s code, including multiple call statements if necessary.
Only the code associated with the field being edited will run. If Automatic Field Calculations cause other fields to be modified, the code associated with those other fields will not run. For example, suppose code has been associated with the Total field, as shown here. You might think that this code would run automatically when you modify data in A, B, C or D, since this causes a formula to run that modifies the Total. However, this doesn’t happen – only the code in the edited field (in this case A) will run.
If you want the code for another field to also run, you must add the runfieldcode statement, like this. This statement has one parameter, the name of the field with the code you want to run.
Note: When a field’s code is run with the runfieldcode statement, the current field is still the original field. So if the code for the target field uses
«» to get the current field’s value, it won’t work.
If you want to run the code for multiple fields, you must use runfieldcode multiple times, like this:
localparameters minValue,maxValue if «» < minValue or «» > maxValue nsnotify "Invalid Value", "TEXT","Value must be from "+minValue+" to "+maxValue endif runfieldcode "Total" runfieldcode "Avg"
As an alternate to setting up code for specific fields, you can also set up a special procedure named
.ModifyRecord that will be run whenever any field is modified. See Tracking Database Changes for more information.
|10.0||Updated||Carried over from Panorama 6.0, but now formulas and code are separate.|