Comments

Everything you can put in a calculation has some kind of value…unless it's a comment. Comments are chunks of text whose sole purpose is to help guide you through long calculations. Professional database developers, like all good programmers, provide lots of comments for the benefit of people who might work on the computer code months or years later. Once you've a few sets of parentheses or nested function calls, you may have trouble understanding even your own FileMaker calculation when you have to go back and make changes. When it evaluates the calculation, FileMaker ignores all comments completelyit's as if they weren't there. (But you'll be glad they are.)

You can use two different styles for your comments. First, any text that comes after two consecutive slash marks (//) is considered a comment. This kind of comment goes all the way to the end of the line.

	// this is a comment
	3.14 * Diameter // and so is this

A comment is also any text that comes between the symbols /* and */. This symbol pair comes in handy in two places. It saves typing if you need to type a long comment across multiple lines:

	/* this is a comment that runs across multiple
	lines. To make life easier, you can use the second
	comment style */

Also, this comment style lets you add comments within a line:

3 /*sprocket size*/ * 10 /*sprocket count*/ * 57 /*tooth count*/

In addition to comments, you canand shoulduse white space to make your calculations easier to read. Calculations don't have to be strung together in one long line, even though that's the way FileMaker does it in the Specify Calculation dialog box. Press the Return key or Space bar to add space anywhere, except in a field name, function name, text constant, or number. Comments and white space can make a world of difference. Here's a long calculation that doesn't make use of either:

	Let([NewText = ":" & Path & ":"]; Case(Item < 0; Let( [TextLen = 
	Length(NewText); Pos = Position(NewText; ":"; TextLen; Item - 1) + 1; Len= 
	Position(NewText; ":"; TextLen; Item) - Pos ]; Middle(NewText; Pos; Len)); 
	Let( [Pos = Position(NewText; ":"; 1; Item) + 1; Len= Position(NewText; ":"; 
	1; Item + 1) - Pos ]; Middle(NewText; Pos; Len))))

Ten points to the first person who can make sense of that mess. Now here's the same calculation, written with more care:

	// Parsing is easier if we can be sure we have delimiters
	// on both ends of the text
	Let( [NewText = ":" & Path & ":"];
		Case(
			// If the item number is negative, we count from the end 
			Item < 0; 
			Let( [TextLen = Length(NewText);
				Pos = Position(NewText; ":"; TextLen; Item - 1) + 1; 
				Len= Position(NewText; ":"; TextLen; Item) - Pos ]; 
				Middle(NewText; Pos; Len)
			);
			// If the item number is positive, we count from the 
			// beginning
			Let( [Pos = Position(NewText; ":"; 1; Item) + 1; 
				Len= Position(NewText; ":"; 1; Item + 1) - Pos ];
				Middle(NewText; Pos; Len)
			)
		)
	)

It may not be a picnic to run through in your head, but it's a lot easier to follow than before.

Part I: Introduction to FileMaker Pro

Your First Database

Organizing and Editing Records

Building a New Database

Part II: Layout Basics

Layout Basics

Creating Layouts

Advanced Layouts and Reports

Part III: Multiple Tables and Relationships

Multiple Tables and Relationships

Advanced Relationship Techniques

Part IV: Calculations

Introduction to Calculations

Calculations and Data Types

Advanced Calculations

Extending Calculations

Part V: Scripting

Scripting Basics

Script Steps

Advanced Scripting

Part VI: Security and Integration

Security

Exporting and Importing

Sharing Your Database

Developer Utilities

Part VII: Appendixes

Appendix A. Getting Help

show all menu





FileMaker Pro 8. The Missing Manual
FileMaker Pro 8: The Missing Manual
ISBN: 0596005792
EAN: 2147483647
Year: 2004
Pages: 176
Similar book on Amazon

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