Working with Field Types
Some of the most important aspects of understanding FileMaker Pro involve comprehending field types, realizing how they differ from one another, and knowing how to use them effectively. Simply stated, field types identify what kind of information each field of your database expects to hold. A person's name is text, the purchase amount for a transaction is a number, a birthday is a date, and so on. Generally it should be quite clear to you what each needs to be.
Field types determine what types of operations can be performed on a given field, what information a field can accept, and the rules by which a field is sorted. The combination of a proper identifying field name and a data type definition is what gives a database its context and meaning.
Text
Text fields are the most free-form of the field types. Users can enter any range of information in them, including carriage returns, and there's no expectation of what form or sort of information a text field will hold. The only requirement is that it be character based—in other words, you can't place a picture in a text field. A text field can store up to 2GB of information, limited by RAM and hard drive space, of course, and indexes up to approximately 100 characters, depending on what language you're using. We'll cover indexing in more depth later in the chapter. For now, simply remember that each field type has different limits and approaches on indexing.
Number
Number fields can store values from 10-400 up to 10400, and negative values in the same range. FileMaker Pro indexes the first 400 significant digits (numbers, decimal points, or signs) of a number field, ignoring letters and other symbols. Number fields can accept text (although not carriage returns), but any text in a numeric field is ignored. FileMaker interprets 12ax3 as 123 if you enter it into a numeric field, for example.
Something to keep in mind with FileMaker Pro: You can express a number field as a Boolean. A Boolean value is either true or false, and often used to test the condition of something. FileMaker Pro treats a zero or null value in a number field as false in the Boolean sense; it treats any other data as true. You will often run across the use of number fields to store Boolean values.
The primary distinction between a number field and a text field lies in how they sort: A text field sorts 1, 10, 2, 20, 3, 4, 5, whereas a number field sorts 1, 2, 3, 4, 5, 10, 20.
Date
Date fields accept only Gregorian calendar dates. FileMaker Pro honors whatever date formatting your country follows by taking the standard your operating system uses at the time you create a new file. Date formats—the order of year, month, and day—are common for a given file. Although it's possible to change the way FileMaker Pro displays dates, it fixes basic ordering at the time of file creation.
Dates in FileMaker Pro are internally stored as the number of days since 01/01/0001. January 1, 2004, for instance, is 731581. If you need to compare dates or perform any functions on them, remember that behind the scenes they're really just numbers. This feature is actually quite handy. To switch a date to a week prior, all you need to do is subtract 7. Date fields can store values from January 1, 0001, to December 31, 4000.
Time
Time fields hold HH:MM:SS.ddd information. Notice that you can add a decimal to the end. An additional useful fact: If a user enters 25:00, FileMaker Pro rightly interprets this as 1:00 a.m. 99:30 becomes 3:30 a.m. The clock simply keeps rolling over. This behavior is useful when you need to add, say, 30 hours to a time, and don't want to be bothered with calculating what hour that becomes. Likewise, if you are doing data entry in a time-tracking system and don't want to create two entries for a case in which you worked from 2:00 p.m. until 2:00 a.m. on Monday (really Tuesday), entering 26:00 for the ending time in your system rightly calculates to 12 hours.
As in dates, FileMaker Pro stores time internally as the number of seconds from 12:00:00 on the current day. 1 is 12:00:01, and 43200 is 12:00 p.m. As it does with date formats, FileMaker Pro establishes your time format during the creation of the file, based on system operating system settings.
The maximum time value you can store in a FileMaker Pro time field is 2,147,483,647. That's a lot of time.
Timestamp
The timestamp data type combines date and time information. It appears as a field with both date and time values, separated by a space: 1/1/2004 12:00:00. As in date and time formats, timestamps are also stored as numbers: the count of seconds from 1/1/0001 00:00:00. Be prepared to work with large numbers when using this field type. Timestamps are an important aid to interoperability with other databases (such as those powered by the SQL language), which often store date and time information in a single timestamp field. The maximum value of a timestamp is 12/31/4000 11:59:59.999999 p.m. or 126,227,764,799.999999 seconds.
Container
Container fields are different from the five already mentioned: They store binary information. Information is often inserted into container fields rather than being entered manually (you can copy and paste). You can place any sort of digital document in your database, limited again by the practical limits of your computer hardware, up to 4GB.
Container fields also support displaying/playing three native types of media: pictures, QuickTime movies, and sounds. Refer to the FileMaker help system for supported formats, but most common image formats are included…as well as some you won't expect. For example, by using QuickTime, it's possible to display and play a Macromedia Flash 5 .swf file. Last, on Windows, container fields support a wide range of OLE objects, including Microsoft Excel documents, PDF, and more. (The first page of PDF documents placed in containers will always be rendered on both operating systems.)
There's one important thing to remember about using container fields: Either you can store the file or media in FileMaker itself, requiring disk space, or you can simply store a path reference to the file instead. If you choose to store just a reference to the file, FileMaker Pro displays the image or file icon as necessary, but it does not hold the actual document. A nice feature of storing references is that you can double-click documents in your container fields to launch them in your operating system.
Calculation
Calculations evaluate formulas and return the requisite results. When you create a calculation field, the Specify Calculation dialog opens, as shown in Figure 3.4. You use the same dialog to specify calculations used for script parameters, web viewers, security privileges, and other purposes in FileMaker Pro.
Figure 3.4 Calculations form an essential part of FileMaker Pro development.
There is a Learn More link in the lower left of the Specify Calculation dialog.
Features of the Specify Calculation dialog box include the following:
- Field list—Select fields to include in your calculation from the list below the table menu. Use the drop-down menu to change from table to table. Note that double-clicking inserts a field into your calculation where your cursor currently sits.
- Operators—Use these buttons to insert math and special operators.
- Function list—Just below the View drop-down menu is a list of functions. Here you're able to scroll through all of FileMaker Pro's various functions and then double-click to insert. It's a good idea to start here to get your syntax correct. The menu above enables you to filter your list by category to show the functions you need.
- Expression text box—This is where you assemble your actual formula or expression. This is a simple text entry area: If you want, work in a text editor and paste calculations here.
- Calculation Result Is list—Calculations return varying information, depending on what data/field type is required. If you want the field to be sortable by alphabet, set the return data type to Text. If you have a field returning, say, a price, set the type to Number.
Examples of calculations include the following:
- 3 + 4 always displays its result of 7.
- Sale + Tax displays the sum of two fields named Sale and Tax.
- Personnel::EmployeeID displays the value of a field in a related table. This type of calculation is sometimes utilized to create a field in a table that takes part in a sort or other routine where you cannot use a related field. In old FileMaker Pro databases, relationships cannot be used more than one table away. Calculations designed simply to provide an in-table copy of a related value frequently litter such databases.
- Position ( Notes; "a"; 1; 1 ) returns a numeric position, starting from the first character in the field Notes, for the first "a" found.
- IsEmpty ( MyField ) returns a zero or one (Boolean) depending on whether MyField has a value in it, including zero. If a zero is entered, the field is technically empty. Only a null value is considered empty.
- If ( MyDate > 900; "yes" ; "no" ) displays a yes for dates entered in MyDate greater than 6/19/0003; otherwise, it displays no (remember that you just tested for the number of days past 1/1/0001).
You can use the Specify Calculation dialog to create a calculation just by clicking fields, operators, and functions. However, you can also type directly into the expression text box. As Figure 3.4 shows, you can spread your calculation out—spaces do not matter except within quotation marks. You can also use indentation to clarify the calculation. Comments can be inserted using two slashes (//), which mean that the remainder of the line is ignored. Multiline comments can be entered starting with /* and ending with */.
→ |
For more detail on calculations, see Chapter 8, "Getting Started with Calculations," p. 249, and Chapter 15, "Advanced Calculation Techniques," p. 433. |
Summary
Summary fields allow you to evaluate information across a found set of records. Sum, Average, Max, Min, and Count are among the summaries you can establish. Don't forget that they apply to found sets: Change your found set, and the result changes.
For example, say you have a table called Transaction, which contains Transaction_Date and Transaction_Amount fields. You can then define and place a summary field on a layout to total the Transaction_Amount field. The summary field adds the values of the Transaction_Amount fields for the currently active set of records. If you perform a find, by date, on 10/1/2006–10/31/2006, your found set will be all the transactions for the month of October, and the summary field will show just the aggregate monthly transaction amount. Perform a different find request and your total changes, reflecting the aggregate of the new found set. Table 3.1 contains a list of summary field functions.
Table 3.1. Summary Field Functions
Function |
Summary Behavior |
Total of |
Adds values from the specified field in your found set. Think of it as a subtotal or grand total from a column of numbers. You can also enable the option to display a running total for your record set. This shows a running tally of your total if you place the summary field in the body area of a list. |
Average of |
Averages the values from the specified field in your found set. The weighted average option enables you to specify a second field to act as a weight factor for calculating the average. The field you choose must be a number or a calculation with a number result. |
Count of |
Counts the number of records in your found set that have data in the specified field. For example, if 18 of the 20 current found records have data, your summary field displays 18. A running count functions similarly to a running total: It displays the incremented count of each record in your found set. |
Minimum |
Returns the lowest number, date, time, or timestamp in a given found set from the referenced field. |
Maximum |
Returns the highest number, date, time, or timestamp in a given found set from the referenced field. |
Standard Deviation of |
Determines how widely the values in the referenced field differ. The function returns the standard deviation from the mean of the values in your found set. The standard deviation formula is n–1 weighted, following the normal standard deviation. Standard deviation comes in two flavors; to perform a biased or n–0 evaluation, select the By Population option. |
Fraction of Total of |
Returns the ratio of a total for which a given record (or set of records, when the field is placed in a subsummary part) is responsible. For example, you can track what percentage of sales is attributable to a given person. The subtotaled option enables you to specify a second field by which to group your data. |
When you create a summary field, the Options for Summary Fields dialog opens, prompting you to choose the function you want to use and the field for which you want a summary (see Figure 3.5).
Figure 3.5 Summary fields are useful for performing functions across sets of records, but use them with care. They can increase the time it takes to load any given layout.
In Browse mode, a summary field evaluates your found set and displays a result when it is actually visible on a layout. For example, if a summary field is below the visible portion of a layout, it displays information only when the user scrolls to that portion of the window. Summary fields evaluate a found set for a given layout whenever you enter Preview mode, which is the logical behavior for printing—the primary use of Preview mode.