Hilite ( SourceText ; SearchText ; R ; G ; B )
This function highlights all occurrences of a specified word or phrase in a block of text.
Average rating: 3.9 (50 votes) Log in to vote
Ray Cologon - Show more from this author
NightWing Enterprises http://www.nightwing.com.au/FileMaker |
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
Locating occurrences of a word or phrase within a large block of text helps users to locate items of interest. This function utilizes recursive syntax to search the source text and apply bold and colored formatting to all ocurrences of the search string (regardless of case).
Because this function modifies the form but not the content of the supplied text, it is suitable for use in an auto-entry calc which sets the field to itself - providing transparent and automatic search and highlighting functionality.
Comments
David Jun 23, 2009 |
||
Ein gut funktionierenes Tool, sehr effektiv programmiert. A good working tool, very short code. Thank you! |
||
Doug Alder, Vancouver Aug 14, 2013 |
||
Seems to crash in FM 12. Tried running it in a script as a Set Field to itself with the search word highlighted. Chugs for a while then gives it up to a crash. | ||
Ray Cologon, San Diego Aug 14, 2013 |
||
Hi Doug, I suspect the problem you are experiencing may lie somewhere else other than the custom function. I have seen it running in a number of FMP 12 solutions without incident. Just to be sure, I just created a brand new v12 file with a couple of fields, added the CF copied pasted directly from this page and set a text field (containing about 20 lines of text) to itself multiple times, highlighting various different search terms. It worked flawlessly each time, no chugging (result was returned instantly) and no crash. Presumably there is something in play in your case beyond the points you've mentioned. Eg how much text is in the field you're running the process on? Does it work with just a few lines in the source field - if so you may be breaching stack overflow limits (which are the same in v12 as in previous releases, FWIW). |
||
Jobst Gmeiner, Darmstadt/germany Jun 4, 2017 |
||
Hi, I am using your function since years. Once in a while, however, I observed that the text in the HiLite-Field doesn't show up. Instead, a question mark appears. Finally, I checked the reason and found out that whenever the length of the SourceText is larger then 10.000 characters the function doesn't work anymore. Is there a possibility to change this, or do I have to split the SourceText in various portions? Regards Jobst Gmeiner |
||
Ray Cologon, Melbourne Jun 4, 2017 |
||
Hi Jobst, I have not encountered the issue you are describing. Just to be sure, I just created a brand new file in FileMaker 16, created a couple of fields, added the CF copied pasted directly from this page and set a text field to contain a number of lines of text and a calculation to highlight search strings entered into another field. It worked flawlessly each time, regardless of the length of the SourceText I supplied (my tests included SourceText strings of over 100 characters and the function continued to work as intended). Presumably there is something in play in your case beyond the points you've mentioned, but it's not clear from your description what that might be. Regards, Ray Cologon |
||
Ray Cologon, Melbourne Jun 4, 2017 |
||
Hi Jobst, My apologies, I now see that I misread your message, and your reference to the SourceText is in EU number notation and you are referring to strings longer than ten thousand characters (we use a different number convention here and I'm afraid I read your message as referring to only 10 characters). The ten thousand character limit is a result of the stack depth limit imposed on standard recursive operations by FileMaker, and this function uses standard recursion, so by its nature it is limited to input strings of ten thousand characters or less. It would be possible to create an alternative function using tail recursion, that could process strings of up to fifty thousand characters (after which it too would fail), but that would require significantly different syntax. Regards, Ray |
||
Jobst Gmeiner, Darmstadt/germany Jun 30, 2017 |
||
Hi Ray, yesterday, I came back to the problem of SourceText limitation again and found your answer. Thank you and sorry for the wrong notation of the number ten thousand. meanwhile I could circumvent the problem with a filemaker script: Whenever I open the file with the SourceText. the script splits the SourceText into portions of 9999 characters, puts them into separated fields with the corresponding HiLite fields. Finally, the HiLite fields were combined again into one field, the hilights are preserved. It works perfect and even fast enough with a file containing more than twenty thousend records. Best regards, Jobst |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.