November 15, 201015 yr For me, this probably applies more to custom functions and using calculations to set fields or variables in scripts (rather than calculation fields). I'm not sure if this was the right place to post this. Anyway, I was wondering if there's anyway to have an infinite series in a calculation. I seem to have this issue all the time. Here's an example: I wanted a calculation that would remove all text between hyphens, including the hyphens, when the text in between the hyphens is less than 50 words, and to separate the remaining text with line breaks. Using my custom function btwn, I have a script write this out, all the way until 250, because I don't foresee ever having more than 250 hyphens in the text to which this would be applied (though sometimes I have to have scripts write out calculations like this, much further) If (WordCount (btwn (text ; "-" ; 1 ; "-" ; 1))>49 ; btwn (text ; "-" ; 1 ; "-" ; 1) & ¶) &If (WordCount (btwn (text ; "-" ; 2 ; "-" ; 1))>49 ; btwn (text ; "-" ; 2 ; "-" ; 1)& ¶) &If (WordCount (btwn (text ; "-" ; 3 ; "-" ; 1))>49 ; btwn (text ; "-" ; 3 ; "-" ; 1) & ¶) &If (WordCount (btwn (text ; "-" ; 4 ; "-" ; 1))>49 ; btwn (text ; "-" ; 4 ; "-" ; 1)& ¶) &If (WordCount (btwn (text ; "-" ; 5 ; "-" ; 1))>49 ; btwn (text ; "-" ; 5 ; "-" ; 1)& ¶) &If (WordCount (btwn (text ; "-" ; 6 ; "-" ; 1))>49 ; btwn (text ; "-" ; 6 ; "-" ; 1)& ¶) &If (WordCount (btwn (text ; "-" ; 7 ; "-" ; 1))>49 ; btwn (text ; "-" ; 7 ; "-" ; 1))... I'm wondering if there's a better way to do something like this. It also seems, that when I do things like this, it takes longer than it should for filemaker to calculate it. If I put something like this in a script that will be used 200 times/day, and it takes 2 seconds to calculate, that's almost a loss of one work-week per year, spent waiting for this calculate. I've already looked at these posts, but they didn't seem to offer a solution: http://www.fmforums.com/forum/showtopic.php?tid/195649/ http://fmforums.com/forum/showtopic.php?tid/183426/ Thanks in advance!
November 15, 201015 yr Well, I did on another forum but apparently I am no longer a searchable term over there... Anyway, a recursive custom function calls itself. Here's a rather primitive example that returns a list of words shorter than 5 characters in given text: ShortWords ( text ) Let ( [ word = LeftWords ( text ; 1 ) ; countWords = WordCount ( text ) ] ; Case ( Length ( word ) < 5 ; word & ¶ ) & Case ( countWords > 1 ; ShortWords ( RightWords ( text ; countWords - 1 ) ) ) )
November 16, 201015 yr You can watch a video on recursive functions here (look for "GetNthRecord Recursion") http://www.itslaves.com/web/guest/filemaker-pro-10-advanced And here's an article that discusses recursive custom functions: http://www.informit.com/articles/article.aspx?p=1013850 You'll also find it discussed numerous times if you search FMForums.
November 16, 201015 yr The best explanation of recursive functions is here: http://fmforums.com/forum/showtopic.php?tid/217720
Create an account or sign in to comment