.NODE

The Calculation Function Interface

The Calculation dialog allows developers easy access to the data fields in their solutions and to a complete function list (see Figure 4.1).

Figure 4.1. Both field names and calculation templates can be double-clicked to insert them into the expression editing area.

If you'd like more detail on calculations including complete examples of how they work, see Chapter 6, "Calculation Functions."

 

Calculations: Things to Remember

When working with calculation fields and the various places within FileMaker that make use of calculation functions, there are some common issues to keep in mind:

  • The four special operators in FileMaker are:

    &

    Concatenates the result of two expressions. 1 & 2 will result in "12".

    ""

    Designates literal text.

    Carriage return.

    ()

    Designates a function's parameter list and controls the order of operations for math expressions.

  • Entering a less-than character followed by a greater-than character (<>) equates to the "not equal to" operator () within an expression. The following expressions are functionally identical:

    2

    This is also true for >= and <= for and images/U2264.jpg border=0>, respectively.

  • If ( fieldOne < 10; "less than 10"; "not less than 10") If( fieldOne < 10; "less than 10"; "not less than 10" )
  • You may insert comments into calculation expressions in two forms:

    
     

    [View full width]

    // this is a one-line comment, designated by two forward-slash characters /* this is a multi-line comment designated in a block by a beginning forward-slash-asterisk and closed by an ending asterisk-forward-slash. */
  • To enter a tab character into an expression (either as literal text or simply to help with formatting), use Ctrl-Tab on Windows, and Opt-Tab on the Mac.
  • FileMaker allows for a shorthand approach to entering conditional Boolean tests for non-null, non-zero field contents. The following two expressions are functionally identical.

    Case ( fieldOne; "true"; "false" )
    
    Case ( (IsEmpty (text) or text = 0); "false"; "true")
    

    Please note that the authors do not recommend this shortcut as a best practice. We tend to believe one should write explicit (and, yes, more verbose) code, leaving no room for ambiguity.

  • FileMaker allows for optional negative or default values in both the Case() and If() conditional functions. The following are all syntactically valid:

    Case ( fieldOne; "true" )
    
    Case (
     fieldOne = 1; "one";
     fieldOne = 2; "two"
    )
    Case (
     fieldOne = 1; "one";
     fieldOne = 2; "two";
     "defaul"
    )
    

    We strongly recommend you always provide a default condition at the end of your Case statements, even if that condition should "never" occur. The next time your field shows a value of "never happens", you'll be glad you did.

  • The Case() function features a "short circuiting" functionality whereby it only evaluates conditional tests until it reaches the first true test. In the following example, the third test will never be evaluated, thus improving system performance.

    Case (
     1 = 2; "one is false";
     1 = 1; "one is true";
     2 = 2; "two is true"
    )
    
  • Functions inserted from the function list in the upper right will at times use brackets to denote either optional or repeating elements.
  • Fields with repeating values can either be accessed using the Getrepetition() function or via a shorthand of placing an integer value between two brackets. The following are functionally identical:

    Quantity[2]
    GetRepetition ( Quantity; 2 )
    
  • While the default menu in the function list says "All functions by name", it does not actually display all FileMaker functions (to the general bemusement of the community). The Get, Design, and External functions are excluded from those listed (and are arguably less commonly used or more advanced than the other functions). In order to view these functions, you'll need to choose to view the desired function group specifically by choosing Get, Design, or External from the menu of function groups.
  • Make careful note of the context option at the top of the Calculation dialog. In cases where the calculation's source table is represented by more than one table occurrence on the Relationships Graph, this menu will become active. Calculation field and expression results can vary depending on the perspective and relationships from which a calculation is evaluated.
  • Note also the data type returned menu at the lower portion of the dialog. It is a common source of bugs when developers forget to choose the correct data type for calculation results. (Returning a result as a number instead of a text type is a common and bewildering bug, at least when you see it the first time.)
  • Turning off the Do Not Evaluate If All Referenced Fields Are Empty option will ensure that no matter the condition of referenced fields at least some value will be returned. This is useful for cases involving, for example, financial data where it's often helpful to see an explicit zero listed in a field.
  • Calculation fields that reference related data, summary fields, other un-indexed calculation fields, or globally stored fields cannot be indexed; otherwise, even though by definition a calculation field returns different results based on different input values, a calculation field can be indexed.
  • FileMaker Pro client computers typically are where calculations are evaluated; however, certain unstored calculations are evaluated on the host or server computer. In cases where certain information relies on a client computer but is evaluated on the server, the server will essentially cache this information when an account logs in and can, at times, be out of sync with conditions on the client. The following functions may be subject to this:

    Get(ApplicationLanguage)

    Get(DesktopPath)

    Get(DocumentsPath)

    Get(FileMakerPath)

    Get(PreferencesPath)

    Get(PrinterName)

    Get(SystemDrive)

    Get(SystemIPAddress)

    Get(SystemLanguage)

    Get(SystemNICAddress)

    Get(UserName)


: FileMaker Specifications

FileMaker 8 Product Line

Specifications and Storage Limits

Field Types and Import/Export Formats

: Calculation Functions

Working with Calculations Primer

Calculation Signatures

Calculation Functions

: Custom Functions

Custom Functions Primer

Useful Custom Functions

: Script Steps

Scripting Primer

Script Step Reference

: Quick Reference

FileMaker Error Codes

FileMaker Keyboard Shortcuts

FileMaker Network Ports

FileMaker Server Command Line Reference

FileMaker XML Reference

: Other Resources

Where to Go for More Information

show all menu





FileMaker 8 Functions and Scripts Desk Reference
FileMaker 8 Functions and Scripts Desk Reference
ISBN: 0789735113
EAN: 2147483647
Year: 2004
Pages: 352
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net