FMPRO-L Archives

January 2013, Week 4

FMPRO-L@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Geoff Graham <[log in to unmask]>
Reply To:
FileMaker Pro Discussions <[log in to unmask]>
Date:
Mon, 28 Jan 2013 14:57:20 +0000
Content-Type:
text/plain
Parts/Attachments:
text/plain (402 lines)
You, know, I started with a custom function; a few things changed my mind: 

1) There was so much script required anyway (for my brute force inelegant method) that the CF didn't make anything shorter or easier to read. If an embedded CF makes the script harder to follow, then it's not helping.. 

2) Debugging a CF in FileMaker is inherently more difficult than debugging a script. Even if I intend to make a CF, I will often start with a script just to get it right first.

3) Scripts are easy to print to PDF and paste into email.

4) The poster asked for help, and a script, being easier to follow and understand than a recursive CF, is more "helpful".

Geoff
	
> -----Original Message-----
> From: FileMaker Pro Discussions [mailto:FMPRO-
> [log in to unmask]] On Behalf Of Nick Adams
> Sent: Sunday, January 27, 2013 2:37 AM
> To: [log in to unmask]
> Subject: Re: parsing a date from a text field
> 
> Wow! What always amazes me is how many different approaches to a
> problem always come up on this list.
> I have learned quite a bit from this list over the years.
> 
> The approach I finally took was that I discovered the custom function
> ExtractPortion ( textField ; prePortion ; postPortion ).
> For my use prePortion = "," and postPortion = "-"
> 
> I used that for my first calc field. That gave me for example Jul 03, 2012
> 
> The second calc field I used LeftWords, middleWords and rightWords to
> insert the slash
> 
> The third calc field I used  case( leftWord = "Jan", substitute "1"  and so on.
> 
> To finish I did a "Replace Field Contents" using the data from the third calc
> field to insert into my date field.
> 
> Thanks again to all.
> 
> 
> Nick
> 
> Nick Adams
> Karystos, Greece
> 
> 
> 
> 
> 
> On Jan 27, 2013, at 1:00 AM, FMPRO-L automatic digest system
> <[log in to unmask]> wrote:
> 
> > There are 4 messages totaling 1354 lines in this issue.
> >
> > Topics of the day:
> >
> >  1. parsing a date from a text field (4)
> >
> > ----------------------------------------------------------------------
> >
> > Date:    Sat, 26 Jan 2013 12:06:35 +0200
> > From:    Nick Adams <[log in to unmask]>
> > Subject: Re: parsing a date from a text field
> >
> > Thank you all for your assistance.
> >
> > I am using FMP 11 Advanced.
> > There is only one comma and one dash in the text. The text before the
> comma and after the dash is of variable lengths.
> > The date is always formatted , xxx xx, xxxx -
> >
> > I am going to try the solutions offered and I will let you know how I made
> out.
> >
> >
> > Nick
> >
> > Nick Adams
> > Karystos, Greece
> >
> >
> >
> >
> >
> > On Jan 26, 2013, at 1:00 AM, FMPRO-L automatic digest system
> <[log in to unmask]> wrote:
> >
> >> Would someone be so kind as to give me a hand.
> >> I am an amateur and only use FMP for my own projects.
> >>
> >> I am trying to parse the date out of a text field.
> >>
> >> The text field contains something like this:
> >> some text, Nov 10, 2006 - some more text
> >>
> >> The date is between a comma and a dash.
> >>
> >> I have been trying various combinations of text functions but cannot get
> anything meaningful.
> >
> > ------------------------------
> >
> > Date:    Sat, 26 Jan 2013 12:55:45 +0000
> > From:    Rowland Carson <[log in to unmask]>
> > Subject: Re: parsing a date from a text field
> >
> > My posting apparently didn't through first time because of an e-mail
> address confusion:
> >
> > On 25 Jan 2013, at 19:14, Bruce Button wrote:
> >
> >> This is a typical candidate for regular expression searching
> >
> > Depending on how unsanitary the other text before and after the date
> might be, I think I'd be inclined to export the field of interest as a text file
> (single field, tab-text format seems best), then do some regular expression
> stuff with BBEdit or TextWrangler (free and nearly as good for many
> purposes). Both come with a great tutorial on GREP search & replace. Once
> the find-replace stuff has been done, re-import the extracted dates into a
> new field in the existing set of records.
> >
> > In some cases I've also found it useful to combine GREP searches with
> AppleScript when I had many files that needed similar processing. I have
> loved FileMaker since the days of Nashoba but sometimes other tools work
> better for certain jobs!
> >
> > in friendship
> >
> > Rowland
> >
> > | Rowland Carson          ... that's Rowland with a 'w' ...
> > | <[log in to unmask]>            http://www.rowlandcarson.org.uk
> > | Skype, Twitter: rowland_carson      Facebook: Rowland Carson
> > | pictures: http://picasaweb.google.com/rowlandcarson
> >
> > ------------------------------
> >
> > Date:    Sat, 26 Jan 2013 17:28:44 +0000
> > From:    Geoff Graham <[log in to unmask]>
> > Subject: Re: parsing a date from a text field
> >
> > # script to find all the dates including 4 digit years and months as text in a
> text field
> > # filename and table names are "parse"
> > # field being read is "In"
> > # date field "Date" will hold the last date in the text
> > # text field "DateList" will list all dates in the text
> > Go to Record/Request/Page
> > [ First ]
> > # let's run through the found set of records
> > Loop
> > # reset the output field from the last run
> > Set Field [ parse::DateList; "" ]
> > # start with this word
> > Set Variable [ $x; Value:1 ]
> > # get a copy of our input that we will be free to murder later
> > Set Variable [ $in; Value:parse::In ]
> > # how many words do we need to look at?
> > Set Variable [ $y; Value:WordCount ( $in ) ]
> > # we're going to loop through each word in the text
> > Loop
> > # word ..
> > Set Variable [ $word; Value:MiddleWords ( $in; $x; 1) ]
> > # could this word be the year we are looking for?
> > If [ (GetAsNumber ( $word ) = $word) and ( Length ( $word ) = 4) and (
> GetAsNumber ( $word ) > 1900 ) and ( GetAsNumber ( $word )
> > < 2050 ) ]
> > # found a 4 digit year
> > Set Variable [ $year; Value: MiddleWords ( $in; $x; 1) ]
> > # find our year in the text
> > Set Variable [ $endpoint; Value:Position ( $in; $year; 1; 1) + 4 ]
> > # and excise it
> > Set Variable [ $dateslug; Value:RightWords ( Left ( $in; $endpoint ) ; 3 ) ]
> > # let's build a date
> > Set Variable [ $day; Value:GetAsNumber(MiddleWords($dateslug; 2; 1)) ]
> > Set Variable [ $month; Value:Let ( x = LeftWords($dateslug; 1 );
> > Case(
> > PatternCount ( x ; "Jan" ) ; 1 ;
> > PatternCount ( x ; "Feb" ) ; 2 ;
> > PatternCount ( x ; "Mar" ) ; 3 ;
> > PatternCount ( x ; "Apr" ) ; 4 ;
> > PatternCount ( x ; "May" ) ; 5 ;
> > PatternCount ( x ; "Jun" ) ; 6 ;
> > PatternCount ( x ; "Jul" ) ; 7 ;
> > PatternCount ( x ; "Aug" ) ; 8 ;
> > PatternCount ( x ; "Sep" ) ; 9 ;
> > PatternCount ( x ; "Oct" ) ; 10 ;
> > PatternCount ( x ; "Nov" ) ;11 ;
> > PatternCount ( x ; "Dec" ) ;12 ;
> > GetAsNumber ( x )
> > )
> > ) ]
> > Set Variable [ $year; Value:GetAsNumber(RightWords($dateslug; 1)) ]
> > January 26, 2013 12:24:02 parse.fp7 - go -1-
> > go
> > # your date, sir...
> > Set Field [ parse::Date; Date ( $month; $day; $year) ]
> > # append that date to the end of the list
> > Set Field [ parse::DateList; parse::DateList & GetAsText ( parse::Date ) &
> "¶" ]
> > # chop off the text up to where we just read
> > Set Variable [ $in; Value:Right( $in; Length ( $in ) - $endpoint ) ]
> > # how many more words do we need to look at?
> > Set Variable [ $y; Value:WordCount ( $in ) ]
> > # since we chopped off the already read part of the text, we need to reset
> the word we were looking at
> > Set Variable [ $x; Value:0 ]
> > Else If [ IsValid ( GetAsDate ( $word ) ) ]
> > # just in case they entered a real date, our word search for years would
> have missed it
> > Set Field [ parse::Date; GetAsDate ( $word ) ]
> > Set Field [ parse::DateList; parse::DateList & GetAsText ( parse::Date ) &
> "¶" ]
> > # and again we have to reset our variables so we can move on
> > Set Variable [ $endpoint; Value:Position ( $in; $word; 1; 1) + Length ( $word
> ) ]
> > Set Variable [ $in; Value:Right( $in; Length ( $in ) - $endpoint ) ]
> > Set Variable [ $y; Value:WordCount ( $in ) ]
> > Set Variable [ $x; Value:0 ]
> > End If
> > # next word please
> > Set Variable [ $x; Value:$x + 1 ]
> > # are we out of words?
> > Exit Loop If [ $x > $y ]
> > End Loop
> > # next record please
> > Go to Record/Request/Page
> > [ Next; Exit after last ]
> > End Loop
> >
> >
> > Geoff
> >
> > From: FileMaker Pro Discussions [mailto:FMPRO-
> [log in to unmask]] On Behalf Of Nick Adams
> > Sent: Friday, January 25, 2013 10:33 AM
> > To: [log in to unmask]
> > Subject: parsing a date from a text field
> >
> > Would someone be so kind as to give me a hand.
> > I am an amateur and only use FMP for my own projects.
> >
> > I am trying to parse the date out of a text field.
> >
> > The text field contains something like this:
> > some text, Nov 10, 2006 - some more text
> >
> > The date is between a comma and a dash.
> >
> > I have been trying various combinations of text functions but cannot get
> anything meaningful.
> >
> >
> > Nick
> >
> > Karystos, Greece
> >
> >
> >
> >
> > ------------------------------
> >
> > Date:    Sat, 26 Jan 2013 17:30:57 +0000
> > From:    Geoff Graham <[log in to unmask]>
> > Subject: Re: parsing a date from a text field
> >
> > Please ignore the pdf page info slipped into the middle of the script...
> >
> > From: FileMaker Pro Discussions [mailto:FMPRO-
> [log in to unmask]] On Behalf Of Geoff Graham
> > Sent: Saturday, January 26, 2013 12:29 PM
> > To: [log in to unmask]
> > Subject: Re: parsing a date from a text field
> >
> > # script to find all the dates including 4 digit years and months as text in a
> text field
> > # filename and table names are "parse"
> > # field being read is "In"
> > # date field "Date" will hold the last date in the text
> > # text field "DateList" will list all dates in the text
> > Go to Record/Request/Page
> > [ First ]
> > # let's run through the found set of records
> > Loop
> > # reset the output field from the last run
> > Set Field [ parse::DateList; "" ]
> > # start with this word
> > Set Variable [ $x; Value:1 ]
> > # get a copy of our input that we will be free to murder later
> > Set Variable [ $in; Value:parse::In ]
> > # how many words do we need to look at?
> > Set Variable [ $y; Value:WordCount ( $in ) ]
> > # we're going to loop through each word in the text
> > Loop
> > # word ..
> > Set Variable [ $word; Value:MiddleWords ( $in; $x; 1) ]
> > # could this word be the year we are looking for?
> > If [ (GetAsNumber ( $word ) = $word) and ( Length ( $word ) = 4) and (
> GetAsNumber ( $word ) > 1900 ) and ( GetAsNumber ( $word )
> > < 2050 ) ]
> > # found a 4 digit year
> > Set Variable [ $year; Value: MiddleWords ( $in; $x; 1) ]
> > # find our year in the text
> > Set Variable [ $endpoint; Value:Position ( $in; $year; 1; 1) + 4 ]
> > # and excise it
> > Set Variable [ $dateslug; Value:RightWords ( Left ( $in; $endpoint ) ; 3 ) ]
> > # let's build a date
> > Set Variable [ $day; Value:GetAsNumber(MiddleWords($dateslug; 2; 1)) ]
> > Set Variable [ $month; Value:Let ( x = LeftWords($dateslug; 1 );
> > Case(
> > PatternCount ( x ; "Jan" ) ; 1 ;
> > PatternCount ( x ; "Feb" ) ; 2 ;
> > PatternCount ( x ; "Mar" ) ; 3 ;
> > PatternCount ( x ; "Apr" ) ; 4 ;
> > PatternCount ( x ; "May" ) ; 5 ;
> > PatternCount ( x ; "Jun" ) ; 6 ;
> > PatternCount ( x ; "Jul" ) ; 7 ;
> > PatternCount ( x ; "Aug" ) ; 8 ;
> > PatternCount ( x ; "Sep" ) ; 9 ;
> > PatternCount ( x ; "Oct" ) ; 10 ;
> > PatternCount ( x ; "Nov" ) ;11 ;
> > PatternCount ( x ; "Dec" ) ;12 ;
> > GetAsNumber ( x )
> > )
> > ) ]
> > Set Variable [ $year; Value:GetAsNumber(RightWords($dateslug; 1)) ]
> > January 26, 2013 12:24:02 parse.fp7 - go -1-
> > go
> > # your date, sir...
> > Set Field [ parse::Date; Date ( $month; $day; $year) ]
> > # append that date to the end of the list
> > Set Field [ parse::DateList; parse::DateList & GetAsText ( parse::Date ) &
> "¶" ]
> > # chop off the text up to where we just read
> > Set Variable [ $in; Value:Right( $in; Length ( $in ) - $endpoint ) ]
> > # how many more words do we need to look at?
> > Set Variable [ $y; Value:WordCount ( $in ) ]
> > # since we chopped off the already read part of the text, we need to reset
> the word we were looking at
> > Set Variable [ $x; Value:0 ]
> > Else If [ IsValid ( GetAsDate ( $word ) ) ]
> > # just in case they entered a real date, our word search for years would
> have missed it
> > Set Field [ parse::Date; GetAsDate ( $word ) ]
> > Set Field [ parse::DateList; parse::DateList & GetAsText ( parse::Date ) &
> "¶" ]
> > # and again we have to reset our variables so we can move on
> > Set Variable [ $endpoint; Value:Position ( $in; $word; 1; 1) + Length ( $word
> ) ]
> > Set Variable [ $in; Value:Right( $in; Length ( $in ) - $endpoint ) ]
> > Set Variable [ $y; Value:WordCount ( $in ) ]
> > Set Variable [ $x; Value:0 ]
> > End If
> > # next word please
> > Set Variable [ $x; Value:$x + 1 ]
> > # are we out of words?
> > Exit Loop If [ $x > $y ]
> > End Loop
> > # next record please
> > Go to Record/Request/Page
> > [ Next; Exit after last ]
> > End Loop
> >
> >
> > Geoff
> >
> > From: FileMaker Pro Discussions [mailto:FMPRO-
> [log in to unmask]] On Behalf Of Nick Adams
> > Sent: Friday, January 25, 2013 10:33 AM
> > To: [log in to unmask]<mailto:FMPRO-
> [log in to unmask]>
> > Subject: parsing a date from a text field
> >
> > Would someone be so kind as to give me a hand.
> > I am an amateur and only use FMP for my own projects.
> >
> > I am trying to parse the date out of a text field.
> >
> > The text field contains something like this:
> > some text, Nov 10, 2006 - some more text
> >
> > The date is between a comma and a dash.
> >
> > I have been trying various combinations of text functions but cannot get
> anything meaningful.
> >
> >
> > Nick
> >
> > Karystos, Greece
> >
> >
> >
> >
> > ------------------------------
> >
> > End of FMPRO-L Digest - 25 Jan 2013 to 26 Jan 2013 (#2013-9)
> >
> **********************************************************
> **
> >

ATOM RSS1 RSS2