Ugo DI LUCA Posted July 13, 2003 Posted July 13, 2003 Hi, This should be fairly simple. RED BLUE YELLOW Assuming I only know the Position of the string I want to substitute, what is the calculation to determine the Lenght of the text entered from the Position Number and the next Carriage Return ? REPLACE(Text, some position, Lenght ?, texttosubstitute) I'm sure Middle(Position) is the way to go but I'm brain dead today.... Thanks.
Lee Smith Posted July 13, 2003 Posted July 13, 2003 Hi Ugo, How about just substituting your text as you said in your question. Substitute(Middle(TextField, Position(TextField, "
kennedy Posted July 13, 2003 Posted July 13, 2003 Ahh, if FMP had some good text functionality with reg-exp's... this would be sooo easy. But instead... Replace(Text, SomePosition, Position(Right(Text, Length(Text) - SomePosition), "||", 1, 1), "text to substitute") Assumptions: 1) For "||" you enter the funky backward P paragraph symbol. 2) You do not want to replace the trailing carriage return. 3) SomePosition either will never be pointing to a carriage return, OR if it is, then you want to replace that carriage return and the following text up to (but not including) the next carriage return. If 2 or 3 is not true, then you may need some plus or minus ones here or there. HTH.
Ugo DI LUCA Posted July 13, 2003 Author Posted July 13, 2003 kennedy said: Ahh, if FMP had some good text functionality with reg-exp's... this would be sooo easy. HTH. SIH -(Sure it Helps ) Thanks to both...
Anatoli Posted July 13, 2003 Posted July 13, 2003 RE: RED BLUE YELLOW Is that text to be replaced unique? Then you can just use substitute.
kennedy Posted July 13, 2003 Posted July 13, 2003 Yeah, I was assuming that he does NOT know the source string content, just the position, otherwise he could have just done Length(MatchString)... but THEN Substitute would be even easier.
cjaeger Posted July 14, 2003 Posted July 14, 2003 Middle(text, yourpos,Position(Middle(text;yourpos,99999);" [par| ",1,1)-1)) should give you the string.
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 OK, I tried all the suggestions, but they don't seem to work as expected. So here's what I'm trying to do. I'm not at my ease with these Middle, Position functions, but I'd like to experiment with these functions. (BTW, Fitch, if you're browsing this thread, could you post back on link you posted once ?) In a file I've inherited, I have a previously checked field with 6 values in it. This would be my "Main Checkbox". At the moment, users are "duplicating" these checks in another record, but according to the order they checked them, the checkbox field could have different content. Main Checkbox Blue Yellow Red Checkbox2 Yellow Red Blue I want the values on this same order they were in Main Checkbox. If a Value "Black" was checked in Checkbox2, it would appear at the end of the 3 previously checked values... Here are my assumptions and calcs 1. Extract the last entry in the checkbox2 LastEntry = Substitute(MiddleWords(Substitute(checkbox2, " ",".spc."), Patterncount(checkbox2, "
Lee Smith Posted July 14, 2003 Posted July 14, 2003 Hi Ugo, I guess you didn't look at the One Line Value List by Don Wieland, that I mentioned in the other thread. It does this TOO. Lee
kennedy Posted July 14, 2003 Posted July 14, 2003 Well, there are two issues here: 1) how to accomplish the bigger goal; 2) how to use text functions to make the edits you're wanting to make. On #1, I should say that I am not a big fan of the built-in FileMaker checkbox mechanism. I think its clumsy and ugly for the user; and even more clumsy and ugly for the programmer/scripts underneath the covers. Rather than a list of text strings concatenated together in random order (just inherently a pain to deal with), I *much* prefer to simply use a Boolean field for each checkbox. Such are painless to use in calculations and scripts, and more efficient. And I implement those Booleans with a graphic checkbox that matches the look and feel of the rest of my solution (in my case, an Aqua look). But for this thread, I'll forget all that, ignore that we're doing this to accomplish some checkbox example, and just try to answer #2, the question regarding how to use the text functions to accomplish the purpose. Unfortunately, from your post, I cannot tell your purpose. You say: 5. Based on the result of 4, I assume the next job would be to a) Insert the LastString in the Position where this string was, sending the Previous value down with one extra CR (not substituting the previous value). or Determine which string was in that Position in "checkbox2", and what length it was, then use the Replace function to substitute it according to its length, and send it in the new position. : As this would be done successively, I surely need to use the Get Field Function, to store the previous "substitutions". Huh? Given the two lists are in different orders, and given the individual entries are each strings of different lengths, substituting one string into corresponding position in the other field is going to result in things like "red" getting plopped right in the middle of "yellow" such that you end up with "yeredw" and such. Is that what you want? Assuming not, please re-explain #5. Or just boil it down to a very concrete example of the before values and what the after values should be. Brian
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 Hi there, Lee, I did and I'd check it back. But this method isn't indexed from what I recall Brian, I also use these settings (with Aqua Look also) for all my checkboxes, and they sure are better suited for the kind of process I'm in. Though, it's a very little adjustment that has been asked to an awful db structure. We'd get to a new structure within the future months. But I need to solve this one. I cannot send the file, but here is a little sampler I'm using for the tests. What you mentionned (having YelRed instead of Yellow and Red is THE problem. Is there some kind of ways to have the position locate the occurence number of a CR instead of the single Position N position.fp5.zip
kennedy Posted July 14, 2003 Posted July 14, 2003 One other question that could make the solution much simpler... will the entries always be single word (no spaces)? Your examples have been, but I wouldn't want to assume that if that's not the case in your real solution.
kennedy Posted July 14, 2003 Posted July 14, 2003 Sorry, another question: If you have main checkbox: RED WHITE BLUE and checkbox2: WHITE BLACK RED what do you want the result to be? RED WHITE BLACK or BLACK RED WHITE or RED BLACK WHITE :
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 Hi, There are spaces, that's why I used Ray's calculation to extract the correct string. Now, working on Christian suggestion, found that : ExtractString = Middle(checkbox2, Position_in_Checkbox1, Length(Middle(checkbox1,Position_in_Checkbox1,99999))) gives me the exact value that needs to be postponed from one CR. So using Length(ExtractString) would be next step. Her's the test back with these. Thanks for the help so far. position2.fp5.zip
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 RED WHITE BLACK So that the Mutikey constructed with the first checkbox could match with 2 of the values from 2. I recall my first words on this thread. It should be simple
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 Ugo DI LUCA said: Now, working on Christian suggestion, found that : ExtractString = Middle(checkbox2, Position_in_Checkbox1, Length(Middle(checkbox1,Position_in_Checkbox1,99999))) gives me the exact value that needs to be postponed from one CR. I just dreamt. So I must quote myself At least you understand what I'm looking for.... lenght of text between Position and next CR ??
kennedy Posted July 14, 2003 Posted July 14, 2003 So, what happens to all the checkboxN fields when the main checkbox changes? For example, main is RED WHITE BLUE and checkbox 1 is RED WHITE YELLOW BLACK and then someone adds BLACK to main checkbox, are you going to go back through all the N checkboxes and resort them? Also, on your example file, the multikey2 field doesn't seem to update properly as I change around the order. For example, if you start with RED BLACK WHITE and then drop BLACK and re-add BLACK, the multikey2 doesn't update properly. Is that intentional? To get down to business here... you are oversimplifying the expression that will be necessary, even given you are just trying to relocate the just-added last element. You are going to have to loop through all the list items that appear in main checkbox prior to the added item and for each check if it is in the checkbox2, if it is then you add that item's length to a total. When you are done with that loop, you have the position at which the newly added item should be *inserted* (not substituted). SetField(checkbox2, Left(checkbox2, pos-1) & NewItem & Middle(checkbox2, pos, Length(checkbox2) - pos - Length(NewItem)) where 'pos' is the position you computed in the mentioned loop and 'NewItem' is the newly added item with trailing CR. I would be tempted to take a very different approach... compute the multikey fields such that they sort as they do the work. That way you get the same multikey no matter what order the input field is in... and you just leave the input fields alone. That approach will avoid the issues when the "main checkbox" gets set. HTH.
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 Brian, Thanks for the follow-up. The Main checkbox won't change. The scripted process you're suggesting is the the one used in my "CheckboxFinds" sampler I've just added 2 days ago. Well yes, this would be the simplest as it also use a sort checkbox function for both keys. As a matter of fact, I've been asked this one for another Project, but I don't have time for a big change of structure. That's why I wanted a calc to convert newly added checkbox to correspond to the Main one. The Multikey is generated at the fly. It's a slight adaptation of DJ's auto create multikey, working with checkbox field. You need to clear the whole field (flag and checkbox content). I've made the change in the second attachment. There are several steps IMO 1. If the checkbox2 is empty, then add the new entry as it appears. 2 If the Total Lenght of checkbox 2 is lower than the Position of the string to be replaced, then add it to the end I believe there are other steps to get the field content with a GetField, and I believe I'm just looking for the impossible here as we would work around the index.... I'll try to figure out a new way to do the job in less time. Thanks for all the suggestions so far.
kennedy Posted July 14, 2003 Posted July 14, 2003 If the main checkbox won't change, then can you hard-code it? If so, the whole thing gets waayyy easier. As for the rest of your message (from IMO on), some of your phrases continue to confuse me. For example "string to be replaced"... that seems to be part of the problem I was pointing out... as I understand it, there is nothing that should be replaced... rather, you want to take the newly added item off the end and *insert* it in the proper place. Thus, I didn't really understand any of the rest of what you're saying. Note that if you know the max size of the field, it is technically possible to unroll the loop I was describing into a calculation... but it'll be a horrific awful monster of a calc. FWIW
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 kennedy said: there is nothing that should be replaced... rather, you want to take the newly added item off the end and *insert* it in the proper place.FWIW Exact. That's what I meant. But how FM *insert* : That's how I guessed we can insert a new string.... As I need to delete the new string from the end of the checkbox, this would be done in 4 parts IMO 1. First replace the "new string" added with ".string." 2. Replace the oldString with ".string2." 3. Substitute (text, ".string2.", "new string"& " "& "old string"). 4. Substitute (text," " & ".string.","") Now, assuming there's a good calc to determine this f.... oldString content or size, based upon its starting position and the CR (which was my 1st question before all this mess... ), the calc above would work for the 2 first entries only. That's why I would need a GetFied (just as the one I use for the Multikey), to store each substiitution and keep the calc go to the others whenever a value is added. Now, I would also need some more If or Case. Ex Blue Yellow 'Yellow' 's Position is 7. If its position in the Main Checkbox was 25, there would be no way to insert it as the current total lenght of checkbox 2 is 12 ! Brian, I really appreciate your feed-back and concern, but I think I plundge my self in the horrible calc you pointed...
kennedy Posted July 14, 2003 Posted July 14, 2003 Ugo DI LUCA said: Exact. That's what I meant. But how FM *insert* : That's how I guessed we can insert a new string.... As I need to delete the new string from the end of the checkbox, this would be done in 4 parts IMO 1. First replace the "new string" added with ".string." 2. Replace the oldString with ".string2." 3. Substitute (text, ".string2.", "new string"& " "& "old string"). 4. Substitute (text," " & ".string.","") You seem to be working too hard. The new item was just added to the end. I want it somewhere in the middle. Assuming I know where I want it moved, the easiest way to move it is to break up the string and reconstruct it as I indicated before: SetField(checkbox2, Left(checkbox2, pos-1) & NewItem & Middle(checkbox2, pos, Length(checkbox2) - pos - Length(NewItem)) where 'pos' is the position you computed in the mentioned loop and 'NewItem' is the newly added item with trailing CR. If you don't know NewItem is on the end of checkbox2, it just slightly complicates the above. But the hard part is knowing 'pos'. In pseduo code, its: pose=Position(maincheckbox, NewItem, 1, 1) if pose = 0 exit pos=1 posm=1 while posm < pose poscr=Position(maincheckbox, "P", posm, 1) if Position(checkbox2, Middle(maincheckbox, posm, poscr-posm), 1, 1) pos=pos+poscr-posm end if posm=poscr+1 end while Unless you can hardcode some things to make unrolling that loop easier, writing this as a FM calc isn't too practical. At the very least, you'll need to make assumptions about the largest number of items. Have fun!
Ugo DI LUCA Posted July 14, 2003 Author Posted July 14, 2003 kennedy said: Have fun! Not sure. At least I solved the main question (I think). Middlewords(your text, 'PositionN
-Queue- Posted July 14, 2003 Posted July 14, 2003 If I had been paying attention this weekend, I could have helped you with the Length function earlier. I've used this type of device many times over. Sorry I wasn't around to assist.
kennedy Posted July 14, 2003 Posted July 14, 2003 Not sure. At least I solved the main question (I think). Middlewords(your text, 'PositionN
Ugo DI LUCA Posted July 15, 2003 Author Posted July 15, 2003 OK Brian, I get the process. Does anyone have a good "tutorial" about the use of these Text Functions. I feel dumb to ask but really something big is escaping me here...
Recommended Posts
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