December 13, 201114 yr Case ( GetFieldName ( _self ) = Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) & Case ( Get ( ActiveRepetitionNumber ) > 1 ; "[" & Get ( ActiveRepetitionNumber ) & "]" ) ; Get ( ActiveFieldContents ) ; _value ) // =================================== /* This function is published on FileMaker Custom Functions to check for updates and provide feedback and bug reports please visit http://www.fmfunctions.com/fid/209 Prototype: AllowInputInAutoEnter( _self; _value; _triggers ) Function Author: Fabrice (http://www.fmfunctions.com/mid/37) Last updated: 15 May 2009 Version: 2.1 */ // =================================== is it me? or is this just crazy writing of functions. I am trying to figure out how some of these functions are working, but when i see this, i just sit back and think about having a few drinks. Can someone PLEASE explain what the heck this is doing? thanks, -i
December 14, 201114 yr Author Dec 14, 2011 10:30 AM (in response to ian.moree) Re: Can someone please explain! Hello, Ian. This is basically looking at the active field and determining if it matches the name that's been passed to the custom function. Let's break it down. Case ( GetFieldName ( _self ) = This says, "If the field name of the parameter '_self' is equal to" ... Easy enough, right? Get ( ActiveFieldTableName ) & "::" & Get ( ActiveFieldName ) This says, "Fetch me the name of the active field's Table Occurrence (not table, despite what the function says), stick the double-colon on the end, then stick the name of the active field on the end." For example, you might wind up with something like "People::FirstName". Case ( Get ( ActiveRepetitionNumber ) > 1 This says, "If the repetition for the active field the cursor is sitting in isn't the first repetition", then ... "[" & Get ( ActiveRepetitionNumber ) & "]" This says, take the active repetition where the cursor is sitting and stick square brackets around it. For example, you might get "[3]" if the cursor were sitting in the third repetition. So, if you had a repeating field and the cursor were sitting in the third repetition, this wouls resolve to something like: "People::FirstName[3]". Now, at this point, the second Case statement ends. Note the "&" between the "Get ( ActiveFieldName )" and the second "Case"? That means, "Attach the results of the second Case statement to my string here." If the second Case statement is false, then nothing gets attached. The first semicolon tells us what to do if the first Case condition is true. That is, if GetFieldName ( _self ) = (in our example) "People::FirstName[3]", then the result of the calculation is Get ( ActiveFieldContents ) - or whatever the field contains where the cursor is sitting. The second semicolon would be our default condition. It's what the calculation will return if all other Case conditions are not true. Since we have only one condition, it's basically a true-false test, but in this case, it will return the parameter "_value" if the cursor is NOT sitting in a field where GetFieldName ( _self ) matches (in our example) "People::FirstName[3]". Whenever I have someone else's code where there are nested Case statements like this, it's often helpful to parse them from the inside out. In this example, you might look at the second Case statement and figure out what it does, then substitute the result to figure out what the rest of the calculation does. As to your other question - could this have been written better - well, I guess that would depend on your definition of "better". Personally, I like using the Let function to simplify calculations like this and to make them easier to read. I might, for example, create variables in a Let statement to parse the Get functions and then use the variables to run through the concatenation. (Especially where the Get functions are called more than once.) I might also create a variable for that second Case statement - calculate it in advance - and then use that instead of another Case statement for readability. But every developer is a little different; they have their own preferences. HTH Mike
Create an account or sign in to comment