September 2, 2010

Fundamentals of Exceptional Interface Design Seminar

by Ernest Koe

Announcing the Fundamentals of Exceptional Interface Design Seminar for FileMaker Developers!

New York City
Oct 13-15, 2010

Register Now! http://vanguardcs.net/craft_of_filemaker.php

read more

Fundamentals of Exceptional Interface Design Seminar

by Ernest Koe

Announcing the Fundamentals of Exceptional Interface Design Seminar for FileMaker Developers!

New York City
Oct 13-15, 2010

Register Now! http://vanguardcs.net/craft_of_filemaker.php

read more

August 26, 2010

Pop: Goes the…um…Variable

by Geoff Coffey

We start our return to semi-regular writing with a small-but-awesome custom function: Pop. If you grew up in the American mid-west like me you might think I’m talking about [soda|soda pop|coke|soft drinks]. But I’m actually talking about stacks. In the computer science world, pop means to take something off the top of a list, and it is exceptionally handy to make it easy in FileMaker scripting.

Looping Through Lists

Imagine you have a list of values. (I know, what a weird concept in a database).

Isabel
Sophia
Mamie
Geoff
Jesse

And you want to do something with these items in a script. Typically, for example, you might want to make a new record for each item in the list. You probably already know that FileMaker has several functions designed to make working with return-separated lists easier. For instance, suppose the list above was in a variable called $names. Here are some functions you might use, and their results:

GetValue($names, 3) => returns "Mamie"
LeftValues($names, 2) => returns "Isabel¶Sophia¶"
MiddleValues($names, 3, 2) => returns "Mamie¶Geoff¶"
RightValues($names, 2) => returns "Geoff¶Jesse¶"

Writing our script using these functions isn’t particularly difficult. Here’s the form we normally use:

# assume $names has a return-separated list of names
# ...
Loop
   Exit Loop If [ValueCount($names) = 0]
   Set Variable [$name, GetValue($names, 1)]
   New Record/Request
   Set Field [The Name Field; $name]
   # set other fields, do more with $name, or whatever*
   Set Variable [$names, MiddleValues($names, 2, 999999)]
End

Note: You might wonder whey I have the Exit Loop If step right after the start of my loop. I do this a lot. It means my loop won’t run even once if the $names variable happens to be empty, which saves me an If step around the loop.

Pop: For the Lazy Programmer In Your Life

We write scripts like this a lot. We pull the first item out of the variable, use it or store it, and then re-set the variable to remove that first item again. Although it is minor, this is non-ideal for a few reasons:

  1. The code is kind of strange. What does this code do? Why all those magic nines?

  2. Any time you write the same couple of lines over and over again, your inner-time-saver-alert should start buzzing.

  3. Call me lazy, but I’m always happy to save a few clicks and/or keystrokes.

And so, we wrote Pop. Here it is:

Pop(variableName) :=
Evaluate(
   "let([
   top = getValue( " & variableName & " ; 1 );
   " & variableName & " = middlevalues( " & variableName & " ; 2 ; 999999999999999 )];

   top)"
)

In a nutshell, this function takes the name of a variable as its parameter. It returns the first value in the variable and removes that value from the variable all in one step.

Note: Pay attention to the previous sentence. The parameter you pass to Pop is the name of a variable, not the variable itself. You want this: Pop("$variable"), not this: Pop($variable).

For the curious, I’ll explain how it works in a moment. But first let’s see it in action. We can now re-write our loop like this:

Loop
   Exit Loop If [ValueCount($names) = 0]
   Set Variable [$name, Pop("$names")]
   New Record/Request
   Set Field [The Name Field; $name]
   # set other fields, do more with $name, or whatever
End

Instead of using GetValue to get the first item in the list, and then removing it later, we do it all in one step using Pop. In fact, since Pop is a function instead of a script step, we can use it right inside other expressions, so we can simplify our loop even more:

Loop
   Exit Loop If [ValueCount($names) = 0]
   New Record/Request
   Set Field [The Name Field; Pop("$names")]
   # *set other fields, do more with $name, or whatever*
End

This time, we get the value, remove it from the variable, and put it in the field all in one step. As a function, Pop can be used in other places too, like inside larger expressions:

Substitute(
   $something; 
   [Pop("$to_remove"); ""]; 
   [Pop("$to_remove"); ""]; 
   [Pop("$to_remove"); ""]
)

Or in recursive custom functions:

If (ValueCount($whatever) = 0; ""; Pop("$whatever") & AmazingFunction

It is often really handy to be able to combine fetching and removing into one tiny expression.

How It Works

The Pop function uses an oft-overlooked FileMaker power-function called Evaluate. This is another one of those meta-features in FileMaker. Evaluate lets you process calculations inside your calculations.

When you write a calculation, you combine functions, values, fields, and operators to produce some useful result. Normally that result is some new data to display or use in your scripts. As you no-doubt know, FileMaker’s calculation engine provides some very powerful tools to process input and produce interesting results.

When you use Evaluate, the result of one calculation can be a calculation formula itself. Here’s a trivial example:

Evaluate("1 + 2")

In this case, the parameter we’re passing to Evaluate is the text value “1 + 2″. Since this is a valid FileMaker calculation, Evaluate will, well, evaluate it, and the final result of the formula will be 3.

Of course that example is silly. If I wanted to add 1 and 2 in a calculation, I’d just write it like this, and save a lot of trouble:

1 + 2

But since this is a calculation, you can get as complicated as you want:

Evaluate(Choose($something, "Average", "Min", "Max") & "(1, 2, 3)")

That equally-ridiculous formula will return either an average, minimum, or maximum of the values 1, 2, and 3 depending on the value of $something.

But why?! Why would I ever do that?

Well, you wouldn’t. But using those techniques, you can do all kinds of other cool things, like, oh, for instance, write Pop. All Pop does is generate a new calculation formula that looks like this:

Let(
   [top = GetValue($my_variable, 1); 
   $my_variable = MiddleValues($my_variable, 2, 99999999)];

   top
)

In other words, it makes a calculation that removes the first item from a variable and returns it. Since we don’t know the name of the variable ahead of time, we have to work the variable name into the calculation using a calculation. (I know, meta…). Once we’ve built this little formula, we use Evaluate to run it for us.

Easy as pie (wrapped in cake, wrapped in an enigma).

Why Would I Ever Use This

If you’re like me, right now you’re thinking this is a lot of work for a very little payoff. It saved a line or two in my loop. But I encourage you to try it out the next time you need to process lists of values. Like all custom functions, it is easy to abstract the complicated part away in your database and never worry about it again, calling on it here and there with an easy name. And that, truth be told, is the core power of programming.

Here, at the End of All Things

by Geoff Coffey

Let me start by saying: “Ouch.” It has been far, far, far too long since our last article. Someone much wiser than me once said something like this: “My only comfort is that I tried. My only regret is that I failed.” I’ll leave it at that.

In short order, I’ll be posting our first new article in over 18 months. But first I thought I’d share a little news. For those who are here for great FileMaker info, feel free to skip ahead. (And let’s be honest, that’s the only reason any of you are here.)

As many of you have noticed, my name is not on the cover of FileMaker Pro 11: The Missing Manual. Since I know a lot of people will ask, here’s the scoop:

I love O’Reilly and we had (have?) a fantastic relationship. I still remember the first O’Reilly book I ever read (The Camel Book), and the awe I felt at its immense quality. It was absolutely an honor to work with a company whose product I respect so much.

It should go without saying, but I love my former co-author, Susan Prosser, who has been a professional associate and personal friend for years. I loved working on the book. The process was hectic, and aggravating, and fun, and wonderful in a million ways.

But writing a book is a labor of love. If you add up all the late nights and killer deadlines and huge work, and divide by the modest revenues, it’s a tough sell. I always considered it worth it because (here comes the honesty) it helped my reputation, helped me sell my services, and was a bit of a thrill. But the calculus has shifted a little. I don’t know how much the book does those things anymore. So when it came time to fire up Microsoft Word (barf) and start in on a revision for 11, I realized I couldn’t justify the stress and life-disruption this time around. This was a personal decision on my part.

In the beginning, I wrote the never-publised FileMaker Pro 7, The Missing Manual over months of long nights. Susan later saved my bacon by revising my manuscript for FileMaker 8 so it could see the light of day. I then had the opportunity to work on revisions for 9 and 10 with Susan. In all, we wrote or revised approaching 3,000 pages, over a thousand screen shots and figures, and a dozen screen casts.

After all that, I would be remiss if I didn’t say this: Thank you.

Thank you to Vince Menanno who convinced me to pursue the project in the first place. Thank you to Tim O’Reilly who blew my mind when he responded personally to the inquiry placed on the O’Reilly web side. Thank you to Susan Prosser who literally saved the book from failure, and made later revisions a joy. Thank you to Stuart Gripman of Crooked Arm Consulting, who ably picked up the reins for FileMaker 11. Thank you to my first editor, David Pogue, who’s early feedback perfectly balanced advice and encouragement. Thank you to Nan Barber, my editor, who made the book much better than it otherwise could have been. Thank you to my family, who surrendered a husband and father to the computer for a few months every couple of years. And thank you to everyone who read the book, especially those of you who left positive feedback on Amazon.com : ).

It is a little sad to watch a big new FileMaker release roll out and not be working on a book. In some ways I miss the crunch, and especially the deep-dive into the minutia of a new release.

Ok, I’m done with all that now. Back to regularly scheduled (Ha!) programming.

Geoff

August 22, 2010

Aug 23 – DevCon Wrap Up

by jsindelar

DevCon Wrap Up

One of the best meetings of the year; we’ll talk about what we saw and what we missed at DevCon 2010 in SanDiego. If you were there, come to share. If you missed it, come to catch some of what went on at probably the best DevCon in a long time.

Next Page →