In fact, Malkie, an A45 field will never contain more than 23 subfields... so here's the complete formula that will work in *any* case :
As I said in my previous message, just copy the formula in the new field and change the cases field in the first line (P1F1 in the example - delete these 4 characters and hit F4 to select the proper value)... P1F1 cases case subfield[cv;" ";23]<>" " of subfield[cv;" ";23] endof case subfield[cv;" ";22]<>" " of subfield[cv;" ";22] endof case subfield[cv;" ";20]<>" " of subfield[cv;" ";21] endof case subfield[cv;" ";20]<>" " of subfield[cv;" ";20] endof case subfield[cv;" ";19]<>" " of subfield[cv;" ";19] endof case subfield[cv;" ";18]<>" " of subfield[cv;" ";18] endof case subfield[cv;" ";17]<>" " of subfield[cv;" ";17] endof case subfield[cv;" ";16]<>" " of subfield[cv;" ";16] endof case subfield[cv;" ";15]<>" " of subfield[cv;" ";15] endof case subfield[cv;" ";14]<>" " of subfield[cv;" ";14] endof case subfield[cv;" ";13]<>" " of subfield[cv;" ";13] endof case subfield[cv;" ";12]<>" " of subfield[cv;" ";12] endof case subfield[cv;" ";11]<>" " of subfield[cv;" ";11] endof case subfield[cv;" ";10]<>" " of subfield[cv;" ";10] endof case subfield[cv;" ";9]<>" " of subfield[cv;" ";9] endof case subfield[cv;" ";8]<>" " of subfield[cv;" ";8] endof case subfield[cv;" ";7]<>" " of subfield[cv;" ";7] endof case subfield[cv;" ";6]<>" " of subfield[cv;" ";6] endof case subfield[cv;" ";5]<>" " of subfield[cv;" ";5] endof case subfield[cv;" ";4]<>" " of subfield[cv;" ";4] endof case subfield[cv;" ";3]<>" " of subfield[cv;" ";3] endof case subfield[cv;" ";2]<>" " of subfield[cv;" ";2] endof case subfield[cv;" ";1]<>" " of subfield[cv;" ";1] endof endcases Regards, Geert. ------- Forwarded message ------- From: [email protected] To: [email protected] Subject: Re: [Dataperf] Extracting Words URGENT Date: Wed, 12 Aug 2009 06:43:23 +0200 Hi all, here is another approach that might suit Malkie, and that stores the last subfield *directly* in a field of the same panel : Create a second (calculated?) A45 field in the panel, containing the following formula: P1F1 cases case subfield[cv;" ";15]<>" " of subfield[cv;" ";15] endof case subfield[cv;" ";14]<>" " of subfield[cv;" ";14] endof case subfield[cv;" ";13]<>" " of subfield[cv;" ";13] endof case subfield[cv;" ";12]<>" " of subfield[cv;" ";12] endof case subfield[cv;" ";11]<>" " of subfield[cv;" ";11] endof case subfield[cv;" ";10]<>" " of subfield[cv;" ";10] endof case subfield[cv;" ";9]<>" " of subfield[cv;" ";9] endof case subfield[cv;" ";8]<>" " of subfield[cv;" ";8] endof case subfield[cv;" ";7]<>" " of subfield[cv;" ";7] endof case subfield[cv;" ";6]<>" " of subfield[cv;" ";6] endof case subfield[cv;" ";5]<>" " of subfield[cv;" ";5] endof case subfield[cv;" ";4]<>" " of subfield[cv;" ";4] endof case subfield[cv;" ";3]<>" " of subfield[cv;" ";3] endof case subfield[cv;" ";2]<>" " of subfield[cv;" ";2] endof case subfield[cv;" ";1]<>" " of subfield[cv;" ";1] endof endcases Note : Add more lines to the formula (up to 45!) if needed, and put the proper field as the case variable ! Regards, Geert. On Wed, 12 Aug 2009 04:49:51 +0200, Brian Hancock <[email protected]> wrote: > Hi Malkie, > There are a number of things in DP, which are not straightforward, > getting > the last word in a string is one. Many programming languages do not have > the > power of many of DP's functions, but the have looping constructions, DO > and > WHILE LOOPS, FOR NEXT loops etc. these allow you to iterate over sets and > lists. These looping structures are how many problems such as the last > word > etc would be handled. > But DP is extremely flexible and there is a very simple technique for > simulating such structures. > I always have a panel in every application I write that has one record > and > only one record. This panel can be used at any point in the application > to > be the target of a created sub report with a virtual link, you can even > nest > sub reports to this panel several layers deep... to get complex > structures > So for the last word it is quite easy. You store the value to be parsed > in > say RV1, you put in a sub report to do some looping, and set a loop > variable > in say RV2, in this case 40 is enough you can only use the up to 78 > character string for the subfield function. You use a formula to extract > the RV2th > --Empty-- > -------------------------REPORT BODY-------------- > -----------------Store Value in Report Variable 1-- > ....> RV1 contains the string or data file to find the last word > ....> eg "The quick brown fox jumps over the lazy dog" > ===============SUBREPORT LINK/PANEL: 0 xx ============= > -------------------------FIRST PAGE HEADER-------------- > -----------------Store Value in Report Variable 2-- > ....> RV2 contains a loop variable, a counter > ....> eg 40 which is big enough here > -------------------------OTHER PAGE HEADER-------------- > --Empty-- > -------------------------TWO-LEVEL REPORT HEADER-------- > --Empty-- > -------------------------REPORT BODY-------------------- > -----------------Store Value in Report Variable 3 -- > ....> RV3 gets the RV2th field > ....> on the first loop when rv2 is 40 then it returns empty string > ....> but as rv2 reduces you get a value > -----------------Store Value in Report Variable 2 -- > ....> RV2 decrements if the RV3 is an empty string, otherwise resets to 0 > ....> IF length[RV3]=0 THEN RV2 - 1 ELSE 0 ENDIF > -----------------Repeat Record if True Is In Report Variable 2 -- > ....> until it finds the a value it will keep looping until RV2 runs out > -------------------------TWO-LEVEL FOOTER--------------------------- > --Empty-- > -------------------------PAGE FOOTER-------------------------------- > --Empty-- > -------------------------FINAL FOOTER------------------------------- > --Empty-- > =========================END OF SUBREPORT=========================== > ....> RV3 contains the last word > -------------------------TWO-LEVEL FOOTER----------------- > The same general technique can be used for many other similar processing > purposes. One major use is for processing an unknown number of fields > and > values in a web submitted form, which might be lines of say a delimited > data > import from a web form. > Brian > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Don Codling > Sent: Wednesday, 12 August 2009 5:30 AM > To: [email protected] > Subject: Re: [Dataperf] Extracting Words URGENT > August 11, 2009 > Malkie, I don't think there is an easy way to do this, because DP does > not allow counting subfields backwards. So you need a formula like this, > in which the highest number equals the maximum number of words in the > target field. Of course each extra line requires an extra "ENDIF". > If subfield[P2F3;" ";8 > "" then subfield[P2F3;" ";8] > elseif subfield[P2F3;" ";7] > "" then subfield[P2F3;" ";7] > elseif subfield[P2F3;" ";6] > "" then subfield[P2F3;" ";6] > elseif subfield[P2F3;" ";5] > "" then subfield[P2F3;" ";5] > elseif subfield[P2F3;" ";4] > "" then subfield[P2F3;" ";4] > elseif subfield[P2F3;" ";3] > "" then subfield[P2F3;" ";3] > elseif subfield[P2F3;" ";2] > "" then subfield[P2F3;" ";2] > else P2F3 > ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF ENDIF > REMEMBER, you have to use the F4 selection to put in meaningful field > names. Aside from that you can copy & paste this, as expanded for your > need, from your word processor. > To get everything but the first word shoud be fairly easy. I have not > tested this, though. > cat.t[subfield[P2F3;" ";2]; subfield[P2F3;" ";3]; subfield[P2F3;" ";4]; > subfield[P2F3;" ";5]; subfield[P2F3;" ";6]; subfield[P2F3;" ";7]; ... > subfield[P2F3;" ";17]] > To get everything but the last word is harder. I have not tested this, > either. But try something like > cat.t[if subfield[P2F3;" ";2] = "" then "" else subfield[P2F3;" ";1] > endif; if subfield[P2F3;" ";3] = "" then "" else subfield[P2F3;" ";2] > endif; if subfield[P2F3;" ";4] = "" then "" else subfield[P2F3;" ";3] > endif; ... {To the highest number of words in your field}] > [email protected] wrote: >> Hi Everyone; >> I desperately need your expertise. I would like to make a formula in a >> field (not in a report) that would automatically extract the last word >> of >> another field, something like with a subfield or substring function or >> whatever. The amount of words in that field are not identical. It can >> vary between 2 and 10 or even more. >> Also, how would I extract all the words of a field besides the last >> word or besides the first word? >> Malkie -- Geert De Baets mailto:[email protected] Web: http://www.debaets.be Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/ _______________________________________________ Dataperf mailing list [email protected] http://lists.dataperfect.nl/mailman/listinfo/dataperf
