iacon_tp Posted July 14, 2010 Posted July 14, 2010 I am using a serial plugin to receive data into a field, I need to manipulate this data so that I get the most recently received reading each time. The data feeds into a holding field, when it populates into the field it appears as either 1 reading, 2 readings or 3 readings at a time with the newest one being the last one to appear in the field. Each reading has a leading and ending identifier (I can't enter them here as the character set isn't supported). The data looks like this: 3.156G 4.541G The leading identifier, 3 spaces, THE DATA I WANT, a G and an ending identifier. Going by the above, my end result would be "4.541" Can anyone help me out with how I will get the data required. I am using the Troi Serial Plugin
Raybaudi Posted July 14, 2010 Posted July 14, 2010 Let( values = Substitute ( Trim ( YourField ) ; " " ; ¶ ) ; GetValue ( values ; ValueCount ( values ) ) )
LaRetta Posted July 14, 2010 Posted July 14, 2010 That wouldn't drop the 'G' off the end. Another possible option would be: GetAsNumber ( RightWords ( field ; 1 ) )
Vaughan Posted July 14, 2010 Posted July 14, 2010 Or Filter( RightWords( field ; 1 ) ; "01234567890." )
LaRetta Posted July 14, 2010 Posted July 14, 2010 Nope. That wouldn't work. KIDDDDDDDIIIIINNNNNNNGGGGGGG! Hi Vaughan!!
Søren Dyhr Posted July 14, 2010 Posted July 14, 2010 Or Filter( RightWords( field ; 1 ) ; "01234567890." ) Isn't there some point in using the layout pulled formatting, the dot makes hardly any point if the receiving field is number, but could make a hell of a difference if the system setting is other than "new world" default. --sd
comment Posted July 14, 2010 Posted July 14, 2010 (edited) You could use = GetAsNumber ( RightWords ( field ; 1 ) ) However, if you are using a comma as your decimal separator, and the input data contains a dot instead (as shown in the OP example) you already have a problem. --- Oops - didn't see LaRetta already suggested this. Edited July 14, 2010 by Guest
Raybaudi Posted July 14, 2010 Posted July 14, 2010 I didn't use a calculation based on the GetAsNumber( ) function because nobody said that an identifier must be a number. What if his system has the comma as a decimal separator, but the identifier isn't a number ( only a sequenze of digit and dots ) ? Also I didn't discard the G because he said: "THE DATA I WANT, a G and an ending identifier." that isn't exactly the same of their next: "Going by the above, my end result would be "4.541"
comment Posted July 14, 2010 Posted July 14, 2010 The way I read it: "..., THE DATA I WANT, [and] a G and an ending identifier."
Raybaudi Posted July 14, 2010 Posted July 14, 2010 ... and now I remember why I didn't use RightWords ( )... If the identifier was a decimal number starting with a dot ?
comment Posted July 14, 2010 Posted July 14, 2010 If the identifier was a decimal number starting with a dot ? Doesn't seem very likely: Each reading has a leading and ending identifier (I can't enter them here as the character set isn't supported). But it would be better if the OP clarified this point.
LaRetta Posted July 14, 2010 Posted July 14, 2010 (edited) "The leading identifier, 3 spaces, THE DATA I WANT, a G and an ending identifier." I read that this is the description of the sequence of how the characters will appear ... the leading identifier, 3 spaces, THE DATA HE WANTS, then a G and an ending identifier. It was clearly indicated the final result of 4.541. BTW, GetAsNumber() drops invalid characters at the beginning, middle or end since FM sees numbers only (or as indicated by Michael, a comma if the OS was so inclined). Invalid characters are not seen as word separators either. RightWords() applied to 313.44 417.22445G would automatically drop the first invalid character because it does not see it as a character. 313.44 417.22445G would be considered two words (only because of the space between) and the calculation I provided will give the result of 417.22445. You can go on until the cows come home but we can only go by the information presented. If the person presenting the data doesn't provide all possible strings then it is their responsibility to come back and provide further detail. Also, a period or dash does NOT belong to invalid character set as was indicated by "Each reading has a leading and ending identifier (I can't enter them here as the character set isn't supported). And sorry, Michael, my response was more directed towards Daniele but overall I was speaking to the both of you. :laugh2: Edited July 14, 2010 by Guest
Raybaudi Posted July 14, 2010 Posted July 14, 2010 I sure misunderstood the sequence and what he considered an identifier. So now, thanks to LaRetta, I understand that the string could be: [LeadingIdentifier][3spaces][TheData][G][EndingIdentifier][LeadingIdentifier][3spaces][[color:red]TheDataHeWants][G][EndingIdentifier] In this case RightWords ( string ; 1 ) may give incorrect value if: [[color:red]TheDataHeWants] starts with a dot [[color:red]TheDataHeWants] ends with a dot The lone sure thing is that there are 3 spaces before the last part of the string. So my calc could be modified to: Let( values = Substitute ( Trim ( YourField ) ; " " ; ¶ ) ; Substitute ( GetValue ( values ; ValueCount ( values ) ) ; [ "G" ; "" ] ; [ "EndingIdentifier" ; "" ] ) ) This can evaluate correctly a string like: 313.44G .44G or 313.44G 31344.G
comment Posted July 14, 2010 Posted July 14, 2010 RightWords ( string ; 1 ) may give incorrect value if: [[color:red]TheDataHeWants] starts with a dot Right. Good catch.
Lee Smith Posted July 14, 2010 Posted July 14, 2010 It might be nice to hear back from the OP. He hasn't been back since he posted his question. Lee
Raybaudi Posted July 14, 2010 Posted July 14, 2010 Yes ! BTW: it is now much time I wanted to ask: what "OP" stands for ?
LaRetta Posted July 14, 2010 Posted July 14, 2010 (edited) OP is 'other person', original poster or sometimes called On Point. I'm joking of course ... it can stand for many things just as LOL can stand for different things. Here's where you will find the answers Edited July 14, 2010 by Guest
Raybaudi Posted July 14, 2010 Posted July 14, 2010 Thank you. I like: Old Patient OutPatient because some times the OP needs to be patient with us till he becomes old. ( or, like an OutPatient, must come many times to the Forum/Hospital ) :
Recommended Posts
This topic is 5304 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