FPScript Functions

23.08.2021

FPScript offers you the option of programming your own functions in FPScript. You can create these as you would regular formulas; however, you need to use the Arguments statement in the first code line to declare arguments for the function. This turns the formula into a function which must be supplied with arguments when called. You can also save these types of functions in template databases, thus expanding the number of FPScript functions.

For example, a function called Sum would appear as follows:

Arguments a, b
a + b

This function can now be called in a different formula:

Sum(1 V, 2 mV)

or

Sum(DataSet1, DataSet2)

The arguments a and b serve as formal parameters to represent the arguments passed. You can use these just like local variables.

You can omit any items in the argument list when calling the function. These items then have an empty data type:

Sum( , 2) is therefore the equivalent to Sum(Empty, 2) and Sum(1) is equivalent to Sum(1, Empty).

Please note that in the function Sum no Return statement is necessary. The result of the last statement in a formula is automatically used as the result of the formula.

Saving FPScript Functions as a Template

If you save an FPScript function in a template database, you can use it in your project databases as you would a built-in function. To save a function, use a wizard in which you can specify a comment for each argument and define the permitted data types and structures. FPScript functions saved this way

are displayed in the wizard for inserting a function into a formula in the Customized category,

are supported by the FPScript Editor's Assistance feature,

support optional arguments with default values, and

when called, automatically check arguments passed for permitted data types and data structures.

Sharing FPScript Functions

FlexPro Professional and FlexPro Developer Suite support shared template databases. You can share FPScript functions that you save in this type of template database with your colleagues. Use the shared template databases to create function libraries for your department or company.

See Also

Custom FPScript Functions Tutorial

Working with FPScript Functions

Creating an FPScript Function

Saving an FPScript Function as a Template

Calling an FPScript Function

Applying FPScript Functions to Data Sets

Share article or send as email:

You might be interested in these articles