Creating and Using User-Defined Functions |
To create a UDF, create a text file called REPPROCS.PRG in the directory where Stonefield Query's data files are stored. Edit this file using any text editor (not a word processor, such as Microsoft Word, which stores binary files, but an editor such as Notepad that stores text files). This file can contain as many UDFs as you wish. Each UDF should start with "FUNCTION" followed by the UDF name and any parameters (in parentheses), and end with "RETURN" or "RETURN <variable or expression>".
Here's an example of a UDF. This function combines three address lines into a single string separated by carriage returns, with blank lines automatically removed.
function GetAddress(Line1, Line2, Line3) CombinedAddress = trim(Line1) + iif(empty(Line2), '', chr(13) + trim(Line2)) + ; iif(empty(Line3), '', chr(13) + trim(Line3)) return CombinedAddress
To use this UDF in a vendor report, create a new report and add the desired fields. Then, turn on the Advanced layout option and click Edit to bring up the Advanced Report Designer. Create a new field and enter the following for the field's expression:
GetAddress(VENDOR.ADDRESS1, VENDOR.ADDRESS2, VENDOR.ADDRESS3)
Save and run the report.