adyf Posted March 19, 2012 Posted March 19, 2012 Could a text calculation be written to remove the LN3615 and the following single character space from the below field to leave 'Helpston Jn to Syston South Jn'. It would be ideal if the calculation could remove all characters up to and including the first space as sometimes the code could be five or six characters. LN3615 Helpston Jn to Syston South Jn BTW I am aware that is it the fact that I have two items in one field that is making this calculation necessary. It's an inherited file and I thought it would be interesting to see the calculation.
comment Posted March 19, 2012 Posted March 19, 2012 Assuming the code is always a single word, you could use RightWords() to extract the remaining text. Otherwise use Position() to find the position of the first space, and Right() to return the following text.
adyf Posted March 19, 2012 Author Posted March 19, 2012 Assuming the code is always a single word, you could use RightWords() to extract the remaining text. Otherwise use Position() to find the position of the first space, and Right() to return the following text. Thanks Comment. Would that be something like this: Right(Position(Section;" ";1;1)-1) Length() doesn't need to be part of this calculation does it?
Lee Smith Posted March 19, 2012 Posted March 19, 2012 RightWords (your field ; 6 ) //if the pattern is always 7 words Length() doesn't need to be part of this calculation does it? Does this mean that the pattern can have more than 7 words?
comment Posted March 19, 2012 Posted March 19, 2012 Length() doesn't need to be part of this calculation does it? Yes, it does.You need to subtract the position of the first space from the overall length in order to get the number of characters you need, counting from the right.
adyf Posted March 19, 2012 Author Posted March 19, 2012 RightWords (your field ; 6 ) //if the pattern is always 7 words Does this mean that the pattern can have more than 7 words? Hi Lee, yes the pattern can have more than 7 words. Yes, it does.You need to subtract the position of the first space from the overall length in order to get the number of characters you need, counting from the right. I'll try and get that into a calculation then :unsure:
LaRetta Posted March 19, 2012 Posted March 19, 2012 Let ( pos = Position ( text ; " " ; 1 ; 1 ) ; Right ( text ; Length ( text ) - pos ) ) Added ... I wouldn't use xWords for things such as this unless you can guarantee that the first character will never be $, #@& ... or any other 'word break' characters. xWords can lose characters that a human considers to be part of the word. :logik:
adyf Posted March 19, 2012 Author Posted March 19, 2012 Thanks LaRetta, I've just learned something else from the way you have written the calculation. It seems that the three steps have been separated onto different lines for ease of understanding. I need to study calculations, particularly when they are encompassed by other calculations. I beleive they are evaluated from the inside out.
LaRetta Posted March 19, 2012 Posted March 19, 2012 (edited) I beleive they are evaluated from the inside out. And that is how you create them ... from the original data backwards (outwards), wrapping with the next function to take the result of the last function and apply the next function until the last step (the most outward) will be the result that you want. There are additional rules of precedence which influence the order of operations called PEMDAS meaning parenthesis, exponent, multiplication, division, addition and subtraction. Let() is the most beautiful function in FileMaker. Period. It allows us to list our thinking clearly (sometimes I use it only for clarity when read by myself later or others, sometimes I use it for clarity as I'm writing a calc; as a chalkboard and test/adjust as I go. Of course Let() especially saves evaluations if the thing being evaluated must happen more than once, and more. Edited March 19, 2012 by LaRetta
adyf Posted March 19, 2012 Author Posted March 19, 2012 Let() is the most beautiful function in FileMaker. Period. It allows us to list our thinking clearly (sometimes I use it only for clarity when read by myself later or others, sometimes I use it for clarity as I'm writing a calc; as a chalkboard and test/adjust as I go. Of course Let() especially saves evaluations if the thing being evaluated must happen more than once, and more. I was actually expecting the outermost calculation to be Right(). Thanks for explaining the Let() function.
LaRetta Posted March 19, 2012 Posted March 19, 2012 Right() IS the calculation of the Let() function ... Let ( pos = Position ( text ; " " ; 1 ; 1 ) ; Right ( text ; Length ( text ) - pos ) ) ... and it could work just as well, written as: Right ( text ; Length ( text ) - Position ( text ; " " ; 1 ; 1 ) ) ... you almost had it and I should have gone your direction (using the second calc) so you can see it. I instead used Let() to show it more clearly but it isn't needed here since every evaluation only happens once. I guess if I had used the second calc then you wouldn't have learned about Let() today, LOL. :jester: 1
Lee Smith Posted March 19, 2012 Posted March 19, 2012 Hi LaRetta, I guess if I had used the second calc then you wouldn't have learned about Let() today I love it when we show them alternatives, after all, we are here to teach as well as learn. Lee
adyf Posted March 20, 2012 Author Posted March 20, 2012 I guess if I had used the second calc then you wouldn't have learned about Let() today, LOL. Just to finish this off, we've established that we didn't need the Let() function in my scenario. Is there anything that Let() does specifically that no other function does?
LaRetta Posted March 20, 2012 Posted March 20, 2012 You can read up on it in FM Help. Let() allow specifying variables which allows for clarity and efficiency because calculations can be declared once in a variable and then the variable can be used throughout. Let() can even be used within Let() allowing complex calculations to be written.
comment Posted March 20, 2012 Posted March 20, 2012 Is there anything that Let() does specifically that no other function does? I believe there is only one: declare variables. Note that it can declare a variable of any one of the three types (var, $var or $$var).
Recommended Posts
This topic is 4688 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