Function editor

Functionality

The function editor allows you to view and/or edit user-defined functions. A user-defined function generally contains of a combination of:

With the editor you can for example:

To open the function editor:

The function editor automatically opens when you create a new function in the Create Function dialog box. The function editor is also opened when you edit an existing function, e.g. by double-clicking a function in the Catalog. For other methods, see How to edit objects.

Parts of the function editor:

The function editor has a menu bar, a description bar, a toolbar, a text pane where the function is defined, and a context-sensitive menu

The description bar and the toolbar can be moved and docked along an edge of the window. You can also make them floating. You can hide or show the description bar, the toolbar and the status bar via the commands on the View menu. These settings as well as the size of the window etc. are stored per function in the registry. The function that is closed last thus determines the appearance of any newly opened function.

Function syntax:

In the text pane, the function is listed as defined in the Create Function dialog box. A user-defined function may contain any combination of MapCalc/TabCalc operators and functions and may use parameters representing maps or columns. The syntax for a function with parameters is:

 

Function FunctionName (ParamDomainType Param [,ParamDomainType Param]) : OutputDomain

Begin

  Return  Expression;

End;

Where:

FunctionName is the name of the function as specified in the Create Function dialog box.
ParamDomainType is the domain type of an input parameter. You can use either Value | String | Coord | Color | Bool. By default, the domain type of input parameters is set to Value.
  • Choose Value when input maps or columns use a Value domain,
  • choose String when input maps or columns use a Class or ID domain or when columns use the String domain,
  • choose Coord when input columns use the Coord domain (X,Y),
  • choose Color when input maps or columns use the Color domain,
  • choose Bool when input maps or columns use the Bool, the YesNo, or the Bit domain.
Param is the name of an input parameter.
Parameter names:
  • must start with a character from A to Z,
  • may contain characters from A to Z, digits 0 to 9, and underscores,
  • may be longer than 8 characters.
OutputDomain is the domain that should be used for the output object (a column or a map) of the function. You can choose any domain available in your data set as well as system domain Coord. By default, the output domain is set to the system Value domain. When you choose a value output domain, the value range is determined by the selected domain.
Expression is the expression that the function should perform, as defined before in the Create Function dialog box.

Mind:

Tips:

  1. You can add remarks in a function by starting a line with rem or // as in:
    rem This is a remark.
    // This is a remark.
  2. For examples of functions, see Map calculation : creating and applying user-defined functions, Table calculation : creating and applying user-defined functions or Map and Table calculation : user-defined functions (advanced).

Although it is not common, you may define functions without any parameters. The syntax for such a function is:

 

Function FunctionName() : OutputDomain

Begin

Return Expression;

End;

Using the function editor

The function editor is a simple text editor similar to Notepad and WordPad.

To cut, copy, paste and delete selections within the function editor:

You can cut, copy, paste and delete texts in the same way as in a text editor:

 

To reverse the last action:

The Undo command regards typing, cut, paste and delete. Using Undo more than once makes the previous Undo action undone.

To search for and/or replace certain characters or text:

You can search and replace texts in the same way as in a text editor:

To save a function:

The syntax of a user-defined function is checked at the moment the function is saved. If there are syntax errors, an error message appears and the function will not be saved.

To save a function with a different name and/or location:

The Save As dialog appears in which you can specify a name and a location for the function.

To print a function or a selection of a function:

The Print dialog box appears in which you can select your printing options, such as the name of the printer, the number of copies, etc.

To select the whole function:

You can now copy the function contents to the clipboard and paste it for instance in a document.

To open the function properties:

The Function Properties sheet will be opened.

To open another function:

The Open dialog box appears in which you can select the function that you want to open.

To exit the function editor:

If the function contains any unsaved changes, you are prompted to save the function before the editor is closed. If there are syntax errors in the function, an error message appears and the function editor remains open.

See also: