Calculations Category

Find Last Occurence In String

Posted by Dempsey in Calculations

The function Position(text, search string, start, occurrence) scans the supplied text for the nth occurrence of a search string, starting where you indicate with start.

Here’s the neat bit: a negative occurrence value causes the scan to go in the opposite direction. The following gives the position of the LAST occurrance of string in text:

position(text, string, length(text), -1)


Calculation: Is Leap Year

Posted by Dempsey in Calculations

This simple calculation returns a boolean of wether the current year is a leap year or not.

Case(
IsEmpty(Current Date), TextToNum(""),
Mod(Year(Current Date),4) = 0
and
Mod(Year(Current Date),100) <> 0
or
Mod(Year(Current Date),400) =0 , 1, 0
)

Force Fields to be Uppercase

Posted by Dempsey in Calculations

Sometimes you may want a field to always be in uppercase characters, however the user may input it. It is possible to just format a field to show the text as uppercase, but the actual field data would remain in lower or mixed case.

To actually force the data to be uppercase we can use an auto-entered calculation.  Open the Manage Database dialog (File > Manage > Database…) and open the options for the field you want to change.  In the Auto-Enter section check the ‘Calculated value’ checkbox and when the calculation dialog opens, type Upper(FieldName) replacing FieldName with the name of the field, or if you are using FileMaker 9 you can use Upper(Self) which automatically uses the current field.

Click OK and then make sure you uncheck ‘Do not replace existing field value (if any)’, otherwise it won’t work.  Close the field options and now all data will automatically be changed to uppercase when the field is exited.