Patrick,
Given the structure of this snippet of code, each newly created record (except the last one) will be committed as a side-effect of the "New Record" step. Therefore, Lorne is correct: a single "Commit Records/Requests" is all that is needed - and it will commit the last record.
On the other hand, placing a "Commit Records", as Bruce suggests, is a good design practice, in my opinion. It explicitly tells the casual reader that we are done with this new record and want to save its contents. It also saves the last new record, which is left open unless we follow Lorne's suggestion; otherwise, the last created record may be lost at some other point, depending on what happens later. Therefore, the best course is to explicitly save each record as we are done with it.
===
Of course, I realize this is just a script snippet - not full blown well written code with the necessary error handling, trapping, etc. Consider what would happen in this script as written if, for example, the records in the target table had either field or record validation added at a later time. In other words, this script may work now, as written and tested, but could fail without warning if the record structure changed at a later time.
Again, I realize this is a script snippet expressing a basic concept, given with the expectation that the reader will use the _ideas expressed_ and incorporate them into their design with consideration for error handling.
Jason
On 7/2/09 at 9:51 PM +0100, Patrick Neame wrote:
> My experience is that you need to do it after each loop. I don't know why, it's just what I've observed.
> On Jul 2, 2009, at 9:19 pm, Lorne & Joan Walton wrote:
>
>> Wouldn't it work just as well if there were a single Commit Records, after the end of the loop?
>>
>> On Jul 2, 2009, at 11:25 AM, Bruce Robertson wrote:
>>
>>>> Set Variable ( $data ; yourGlobalField )
>>>>
>>>>
>>>> Loop
>>>> Exit Loop If [ isEmpty( $data) ]
>>>> New Record
>>>> Set Field ( Yourfield ; GetValue ( $data ) ; 1 ) )
>>>> Set Variable ( $data ; middleValues( $data; 2; valueCount( $data) )
>>>>
>>>> End Loop
>>>>
>>>>
>>>> --
>>>> Bruce Robertson
>>>> Concise Design
>>>> FileMaker 9 Certified
>>>
>>> Oops, don't forget Commit Record after Set Field.
>>>
_______________________________________________
FMPexperts mailing list
[hidden email]
http://lists.ironclad.net.au/listinfo.cgi/fmpexperts-ironclad.net.au