|
|
|
Navigate: | My Mac Online | The Archives | September 1999 | FileMaker 101 - Part 18 | |
![]() |
|
![]() Part 18
My Mac Magazine manavesh@mymac.com Labelling & Troubleshooting Fields, Calculations, Relationships & Scripts In this article I'm going to give you a few tips on how to organize your database. In the rush of creation we often neglect these simple steps to document our own work. Then later we pay the price, as we've forgotten exactly what all those darn things are and what they do. The first step in keeping track of what things are is to name them, and the first things to name (other than the files themselves) are the fields. There are, as far as I can tell, two main systems for naming fields.
Alphabetical Field Names
*(Self_Service being the name of a self-relationship of the Job ID) As you can see, there are several fields beginning with "Serv". Choosing view by Field Name in the Field Definitions will instantly bring them together. You can adjust the order somewhat by using different punctuation. Sticky spaces between the words will also work, adding the advantage of keeping the words together in calculations. I often use that for IDs, since the extra space helps them stand out in lists. (But I'll spare our webmaster and just use regular spaces here.) I also use the sticky space and a short suffix to identify types of fields. For example; " g" for global fields, " c" for calculation, " gc" for concatenated globals. That way I can quickly tell them apart from a regular field with the same name. One problem I've found is to keep the distinction between actual Summary fields and Total fields which are based on aggregate functions. They are not always the same; the Summary depends on the found records, while an aggregate using a self-relationship does not. So I always use the letters "Sum" for Summaries and "Total" or "TOT" for Sum() aggregates. You could do it either way, but... It is important to be consistent. If you name some fields carefully, but just slap on the first thing that comes to mind on others, you will soon have little idea what does what. It can get pretty sticky if there are a lot of fields with similar names. If you find it getting out of hand it's time to move up the next level of organization.
Custom Order Field Names A further refinement to this method is to name fields with a prefix to show the type of field, much like I did before with suffixes. "g Job ID", "g Service", etc.. If you do an alphabetical sort it will sort by "Type" of field as well.
Obsolete Fields Never delete a field if there is an Import order in a script. It will screw up the Import in a way that is very difficult to fix. Just change it to a global field and leave it. It will then be empty and unstored. If you need a new field later, just rename and redefine it. You could also use the "False Calculation" method (two paragraphs down) to tell yourself just why you "retired" the field. Conversely "#" and "•" prefixes will sort to the top. This is also a great way to track a field that may be referenced in other fields' definitions. Temporarily rename it, then scan the Field Definitions. It will stand out like a sore thumb in other fields' calculations.
Custom Separators [Warning: the next two techniques are geeky.]
"False" Calculations
For example:
Disabled Auto-Enter Options Relationships Now that we've got our fields under control, let's move on to relationships. When I was beginning, I tried to name relationships with names that described what they did, their function in the file. But I would forget what the necessarily short name meant. And then, to make things worse, some relationships were used for several different operations, or a similarly named relationship went to a different file. So now I name the relationships according to where they go (files) and what fields are involved, trusting that I can figure out what it might do by looking at the context of how it is used...and by reading my Comments in the scripts.
Relationship Names Rather than name relationships within the same file with the file name, I prefix them with "Self", as in "Self-Client ID" (Contacts file), or "Self-Job ID" (Jobs file); whatever the field involved is named. One of the great advantages of naming clearly like this is so you can pick the right one when choosing a relationship in the drop-down box for a field, in either a field definition, or in a calculation dialog. If you still can't tell what a relationship does, go ahead and choose it, then click again, drop down to the bottom of the list box, to "Define Relationships," and let go. The relationship dialog will open, already scrolled to that one, so you can see which fields are actually involved. If it's what you wanted, just close the dialog. (An excellent piece of software engineering.) If you still can't tell, it may require a trip to the Field Definitions and a study of the field(s) involved. Try to remember where you are before going that route, as you'll need to get back.
Relationship Order Scripts Now we get into the really fun stuff. Carefully naming scripts and documenting script steps is the only way to preserve your sanity. The problem is not too awful at first, but wait a little while, then come back and try to modify a complex script. You won't remember exactly what's happening, much less the unforeseen effects on other scripts--and I don't think it's only me that has this problem. Fortunately FileMaker has a few ways to help. The first is to use a system to name your scripts. The names can be pretty long, and there aren't really any restrictions on characters you can use, so there's less need to be cryptic.
Script Groups Above each of these groups is an easy-to-see label. The label is basically just an empty script; just delete all the steps. Name the scripts with a few dashes or underlines then the group name. "------------- Navigation" would be scripts that just deal with moving around the file. "--------------> External", scripts that go to, or call scripts in other files. "-------------< External", scripts that get called from other files. "-------------- Printing", "----------- Help Messages", etc.. The dashes set the names off to the right of the regular script names, so they are more visible. Drag the label above the groups. Duplicate one to make another. Often a single dash is used as the name of an empty script to create a separation line in the Scripts Menu list visible to the user. Just click the "Show in Menu" checkbox for those. Don't check it for these other ones.
Script Names To make them easy to see, I use a long arrow, "-->", or "<--" for external scripts (sometimes "<-->" for one that goes then returns). I also include at least one of the file names of the external file(s). Eg., -->JobEntry, Job Choice Lay This tells me that this script just goes to the JobEntry file, to the Job Choice layout. If a script calls another script within its own file, I just use a single arrow after it. I try to put the script it calls directly under it, with an arrow in front.
New Record> This tells me that the New Record script runs a custom scripted check for empty fields before allowing me to create a new record. Another way to write the first, if several scattered scripts called the same subscript (very likely), would be, New Record >w/Empty Check. Another script might be, Main Menu >w/Empty Check. This makes your life much easier if you ever modify a script. You can see that there will be effects on other scripts. It's especially useful when you are checking scripts between files, when the name is all that you can see easily from the other file.
Comment Step
External Scripts By the way, if the script you see in the dialog doesn't have its "<--" arrow, then you have either neglected to name it properly, or you're calling the wrong script. This is especially important in simple scripts that have slight variations but similar names. Sometimes the externally called one has only a single difference (such as a Halt Script step); unless it's labelled you can't pick it easily from the other file.
Troubleshooting Scripts Another quick way to "hear" what's going on is to add a Beep step. It's especially useful to see "if" something is happening at all. Add two beeps or three beeps to check other possible branches of a conditional script. If you think that a step (or series of steps) are the problem, and you would like to run the script without them (assuming it could), there is a way to "comment them out."
Put a false "If" step before them, and an "End If" after.
Obsolete Scripts If all fails and you're still not sure whether it's being used, leave it in. The possible damage from removing it is worse than the small disk space being wasted by leaving it in. Speaking of wasting space, I'll see you next month.
Fenton Jones
FileMaker 101 - Previous Columns
|
|
Copyright ©1995-2000 My Mac Productions, All Rights Reserved |