Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
The great thing about Recursion is it can adapt to change. Our phone length could change depending on the country or whether somebody enters an area code or not. So we've already added the Recursor formula to our database and we're going to review it, but let's start by looking at how it is called inside the Calculation Engine. So we'll go to Manage, Database, we'll go down to our phone field, and we've done it to phone and phone s, both of them, same thing, go into our Calculated Value and we can see we called PhoneFormat. That is now a Custom function. We've imported it and remember that FileMaker 11 can Copy and Paste or import Custom functions, you know, I didn't type it all over again from scratch, I actually imported it. So, there it is right there - PhoneFormat needs a Phone and the Format. We provide the phone using Self which means the phone here and then the format we want so it works a lot like that Plugin we saw and that's the basic idea. Works almost, you know, it's reversed from the Plugin. We had the, the Plugin has a format over here, but it's basically the same idea. We can type in anything we want here, any kind of formatting as long as we have pounds for numbers and formatting can be anything else. We're set, we can type in anything we want in here, or provide it with the Contents of Field as we'll see later. So that's it. It's very simple to call. Now let's go look at the Custom function. So again, here is your import feature and to copy and paste you use the keyboard commands, so we'll look into the PhoneFormat and the first thing we want to see is the function name and then the two parameters and then we look down at our formula. It starts off with a Case statement. Now you'll see that there's a Let function down here. You don't have to have Let function on the outside always. Sometimes you're going to have the, you know, it on the inside, it's up to you. I generally put it on the outside but it's really up to you how you do it and I want to give you an idea how it works here. Now there are two Case statements in here as you'll see. The inner Case statement decides whether we have formatting or a number, so remember, as we're going through this and we're going to put some examples up here, this might be the data, pound pound pound for the formatting -pound pound pound dash, there we go and then their phone number might be something like 909 393-4664, there we go. So the idea is that it has to look at this character here and if it's a pound that means we want to grab a number but if it's formatting we just want to grab the formatting, so that's the basic idea how this works. So let's go through it remembering that basic construct here. So what this Case statement determines is whether we should recurse or not. Eventually, as you're going through this you're going to be lopping off these formatting characters. Once you've looked at this one you're going to take it off and call it again, you know, call the Recursion again. Take another one off, call the Recursion again. So, eventually that format will be empty and when it's emptied then we're going to stop recursing and we're done formatting that phone number. So, let's take a look at the actual thing, so if it's true that there's something still in the format then we're going to run all this stuff here. There's a null result, you know, that it won't call itself again if it's, the format has something or is empty at that point. Then we have some declarations. These should be pretty familiar. We have AtNumbersOnly, it's a little bit different on the Name here, but it's the same idea, filter out all the formatting, just give us the numbers. Then we have two new ones here: AtNewFormat and AtNewNumber. Now these are very important to understand. They're used to call back to itself, and you'll see it down here and we'll explain that later but once you understand, just understand this outside of really the idea of this whole Recursion and then you can put it in place, you know, in context with the Recursion. So first don't worry about how it applies here so much. AtNewFormat says take the Left of the Format, OK that's this parameter right here and get the Length of the Format and subtract 1. It essentially removes the last character and let's see how that works. So, if we're looking at the formatting it's going to say look at the length of this formatting, which will be 12 characters, subtract 1, which is 11, then go from the left and grab 11 characters, essentially removing that last character because we're going to keep lopping off characters so the next time once we lop something off we're going to get that much and then we're going to lop another one off and then we're going to get that much and that's how we go ahead and pass back into it what we need to pass back into it. Same thing works with the AtNewNumber, just with the number values. We're going to keep passing in one less value each time we call it. Now if you understand that it's fairly easy to understand, now let's see why we need to do that when we look at the actual Recursion portion. What we do is we check here in another Case statement to see is the Right of the format a pound sign? Is it formatting? If it is, then we're going to do this part of the formula right here. We're going to say, call back to PhoneFormat and pass into it AtNewNumber, which means it'll take off 1 character and AtNewFormat which will mean it will pass in 1 less formatting character. And then we're going to concatenate on the right-most number, that's because if we found a pound it must be a number, we want to put into our stack, you know, what we're building up with this Recursion, that number. So here's the idea. It sees that it's a pound so what does it do? It uses AtNewFormat and AtNewNumber, so it lops off 1 and then in our stack we're going to get that number down there and we're going to keep going through it and keep adding to our stack and keep removing from this. So we'll go ahead and put that back in there. Put in the pound sign again. Come down here. If it's not a pound sign we're going to do something similar but a little bit different. We're going to call PhoneFormat again with AtNumbersOnly because we found some type of character here but we're not calling it with new number, we're calling it with that, we don't want to lop off a number because we found some type of formatting, that means you don't want to take that number off because we're not substituting it for the formatting, we're taking that directly from the formatting, we're directly taking this type of formatting value here or anything you might put in there. But we do pass in the new format minus 1 of those and then we say take from the format, take one to add to our stack and then we end the Let and end the Case. So let's take an idea, you know, let's work through this and see how it works. First thing it's going to go and look at, there's a pound, so it's going to go ahead and take off 1, take off 1, put that number down there. It's going to see it's a pound again, take 1 off, take 1 off, call itself again, put that number in there. Take it off, take it off, put that number there. Take it off, take it off, put the number there and this time it's going to go, oh, I have a dash. OK, I'm just going to take off the dash, add it here, but not take off the number and pass it in and you can see how it keeps building it up until this is empty and obviously when this is empty then the number will be empty. So, that's the basic idea behind this and you really should type this in to really get an idea of how this works because it'll really help you when you're typing in to really see each detail and give you a chance to really think about it rather than just copying and pasting it. But if you wanted you can always go to the Work Files to the End folder and you'll see this formula in the End file.
| Course: | FileMaker Pro 11: Advanced |
| Author: | John Mark Osborne |
| SKU: | 34140 |
| ISBN: | 1-936334-36-4 |
| Release Date: | 2010-07-09 |
| Duration: | 14.5 hrs / 159 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |