Anuviel Posted April 3, 2009 Posted April 3, 2009 I need to make a script that would loop through a field which contains text, each sentence separated by carriage return or a value list... The script should go to the first value, add it into a variable then continue onto the next value, add it to a new variable and finally exit after last. I do not know how long the list will be or how many values will be inside, it will wary. If the script cannot create dynamic variables (IE. Var1, Var2 Var3 based on how many values there is)the script could set Var1 with the first value from the list, then preform what is has to do, then go to second value in the list and repeat. I got as far as making a script that will get the first value into a variable. I do not know how to get it to go to second except by hard coding it but I do not prefer doing that as the list might have 50 or 1000 values so it does not seem practical. I also thought of having the script delete the first value after it is done, then restart as the second value would become first value? Any thoughts or pointers appreciated... Thanks.,
comment Posted April 3, 2009 Posted April 3, 2009 Variables have repetitions, and this seems like a good opportunity to use them. BTW, I wonder what will you do with all those variables, once you have them.
Anuviel Posted April 3, 2009 Author Posted April 3, 2009 (edited) The post I made yesterday http://fmforums.com/forum/showtopic.php?tid/202602/ I was working on achieving a comparison between characters. Basically what I made is that any text entered into a field will be separated; each char on one line in a new field. So if you enter "This" into a text field, second text field will show that as T h i s Then for a text I want to compare, the same thing so if I enter "Rhis" I get R h i s I then run script which gets first value into variables so var1 = T and var2 = R. I made a calc which compares the two and if they are the same it puts T into a new field, if They are not then it puts R. So basically I am looking for a way to get the script run through all of the values in the field in which the text is separated. That way I can compare the two words and highlight the individual chars which do not match. I know that it is not a solution or might not be good at all but taking on things like this makes me learn new aspects and functions of FM otherwise I always end-up using what I already know over and over again, no chance to learn new stuff. I still gotta figure, if I can get the script working, what happens when This is in one field and Apples are in another... Thanks, appreciate the help. Edited April 3, 2009 by Guest Misspelled know (now).
comment Posted April 3, 2009 Posted April 3, 2009 I think you could compare the two texts directly, without going through all this rigmarole. I assume you are using a custom function to turn each character into a value - you could have the same function do all the work, without needing a script, variables, etc. I made a calc which compares the two and if they are the same it puts T into a new field, if They are not then it puts R. Wouldn't that always return the second text?
Anuviel Posted April 3, 2009 Author Posted April 3, 2009 Yes - it would always return second text. Highlighting the chars that are different from the ones in the first text. This is an apple. - original text This is a orange - comparison text The value returned would be This is [color:red]a orange That way I could quickly see what parts of the modified text are different from the original. I am actually not using a custom function, I am using a Substitute function to separate chars. I could probably use a better way of separating but do not know how...using the substitute function I have to hard-code all keyboard chars, signs...for example: Substitute ( Text1 ; ["T";"T¶"] ; ["h";"h¶"] ; ["i";"i¶"] ; ["s";"s¶"] ) Not sure how I could do a custom function to take care of everything, not on that level yet (hopefully someday I will be).
comment Posted April 3, 2009 Posted April 3, 2009 using the substitute function I have to hard-code all keyboard chars, Correct. And it's not necessary, because you could make your script do roughly something like: Loop Set Variable [ $i ; $i + 1 ] Exit Loop If [ $i > Max ( Length ( TextA ) ; Length ( TextB ) ) ] Set Variable [ $result ; $result & Case ( Exact ( Middle ( TextA ; $i ; 1 ) ; Middle ( TextB ; $i ; 1 ) ) ; ... ) ] End Loop Set Field [ Result ; $result ] Of course, the problem with the entire concept is comparing "apple" to "aple".
David Jondreau Posted April 3, 2009 Posted April 3, 2009 This is an apple. - original text This is a orange - comparison text The value returned would be This is [color:red]a orange Out of curiosity of what you expect this function to do, shouldn't the above be: This is a[color:red] orange
Anuviel Posted April 3, 2009 Author Posted April 3, 2009 Thanks, will give it a try. Will post the results. Of course, the problem with the entire concept is comparing "apple" to "aple". Yes indeed.
Anuviel Posted April 3, 2009 Author Posted April 3, 2009 Yes, sorry, highlighted the a by mistake, it seems. :(
Anuviel Posted April 3, 2009 Author Posted April 3, 2009 Ok, here is a crude draft of the file. Basically it compares characters in the order in which they are entered to one another, coloring the ones in the modified text. It is not working as intended but nevertheless it is working... Thanks., Test0005.zip
Anuviel Posted April 3, 2009 Author Posted April 3, 2009 Ooops, forgot to mention it only works for Capital letters, 0 - 9, space and . Due to my use of substitute, hard-coded only those...
Søren Dyhr Posted April 4, 2009 Posted April 4, 2009 You have obviously not taken much notice of Commets suggestion, since you in your template without hessitation continues to transform your data so GetValue( can deal with it, what would be the advantage of doing so? You could BTW instead of the massive substitution of an array of values into the same value with a pilcrow postfixed, really do it more compactly: Let(tt=Replace ( input ; Length(LeftWords(input;1)) ; 0 ; "¶" ); Case(Length ( GetValue ( input ; 1 )) > 2;CF_Word_monger(tt);tt)) ...allowing more charater types - provided the CF deals with just one word only! --sd
Recommended Posts
This topic is 5713 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now