November 18, 200520 yr I'm trying to design a custom function to perform a variety of text manipulations (defined by codes) and am having trouble at the first step. Here are sample fields and their values: Input: This is a test Operation: Input [1,1] I want to pass the contents of Operation to the custom function (Textract) and have it recognize and treat the first word (in this case, Input) as a valid field name. The values in the brackets will eventually describe the text operation to be performed, but I'm not there yet. So for now I have a calculation field (Result) Result = Textract (Operation) Textract is simply (and wrongly so far) defined like this: Let([ $field=GetField(LeftWords(Input;1))] ;$field) What I want to do is return the _contents_ of Input (This is a test), not just the name of the field (Input). When I can do that, I can begin on the text operations. How can I do this? Thanks! James McAlister www.BulletinInserts.org www.james-mc.com
November 18, 200520 yr try with using a scripted: GetNthRecord ( fieldName ; recordNumber ) For example, SetVariable [$Field; Value: GetNthRecord ( Input ; Get(RecordNumber) )
November 18, 200520 yr Author Thanks, Breezer. Yes, I see how to set a variable with a script, but I really need to pass text to a custom function and have the function recognize the field name (that will be part of the text passed) and use it as such. It needs to be a standalone function that doesn't rely on scripts.
November 18, 200520 yr Field names in custom function are a thorny issue: http://fmforums.com/forum/showtopic.php?tid/169791/ http://fmforums.com/forum/showtopic.php?tid/170873/ http://fmforums.com/forum/showtopic.php?tid/171104/ However, in most cases they shouldn't be required. I am not too sure what is it that you're trying to accomplish here - perhaps if you explained the purpose, another way might be found.
November 18, 200520 yr Your function works fine if you define it properly. I think you are muddying the waters by thinking about the names of the field you intend to use. Try Textract(field) = Let(f = GetField(LeftWords(field;1));f) Obviously just to do this step you don't need the Let and the f you could just define Textract(field) = GetField(LeftWords(field;1)) but I assume that once this bit works there is going to be more work later in the function.
November 19, 200520 yr Author Thanks for the links, Comment. I need to study them more closely. What I'm trying to do is formulate a custom function that would simplify a variety of text manipulation operations that I now do with repeated applications of Position, Length, Left, LeftWords, Middle, etc. I would want to pass a field name to the function along with the operation defined by brackets. Example: InputText[2,8] would return 8 characters of InputText beginning with the 2nd character. Example: InputText[-1,-4] would return the last 4 characters of InputText. The -1 indicates beginning with the last character and then working backward 4 characters. Stringing operations together (e.g., [2,8][-1,-4]) would perform the first operation and then pass the results to the second. Years ago I used Panorama, which had a very handy feature called Text Funnels for taking text apart. I was thinking of a custom function that would do something similar. Hope this makes sense.
November 19, 200520 yr Author Thanks, SlimJim. I do have something crude working, sort of, and I appreciate the pointer which nudged me along a bit. :)
November 19, 200520 yr I may be missing something. Do you want to hardwire the field on which the function operates? Usually, the field name will be passed as a parameter to the CF when defining the calculation field. This makes the CF flexible, so that you can re-use it with any field serving as the text source. Your function, IMHO, should look something like this: InputTextCF ( text ; start ; numberOfCharacters ) = Case ( start > 0 ; Middle ( text ; start ; numberOfCharacters ) ; ... Later, when you define the calculation field, you will replace the text parameter with YourFieldName. Otherwise, you will have to define (hard-wire) the text inside the CF, like this: InputTextCF ( start ; numberOfCharacters ) = Let ( text = Evaluate ( "YourFieldName" ) ; Case ( start > 0 ; Middle ( text ; start ; numberOfCharacters ) ; ... But the calc will have to be unstored, and you will have refresh issues even so.
November 19, 200520 yr Author Yes, I want to pass the field name as a parameter and now see how to do that. I believe that part of my problem was that I didn't have the calculation set to unstored. Now I do. I'll continue to work with this and will post what I come up with if it appears useful. Thanks for the help and the examples.
November 19, 200520 yr If you pass the field name as a parameter (as per my first example), then the calculation can be stored.
Create an account or sign in to comment