repeat with

Ken Ray kray at sonsothunder.com
Thu Jan 12 22:02:56 EST 2006


On 1/12/06 8:34 PM, "liamlambert" <liamlambert at mac.com> wrote:

> I am trying to tidy up this code with repeat but haveing trubble
> This works fine
> get field "name1"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "phone"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "child"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "adult"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "total"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "credit"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "paymenttype"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "address"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "address1"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "address2"
>    put "'" & cleanSQL(it) & "'" & "," after tRowData
>    get field "email"
>    put "'" & cleanSQL(it) & "'"  & "," after tRowData
>    get field "seatNo"
>    put "'" & cleanSQL(it) & "'"  & "," after tRowData
>    get field "ticket"
>    put "'" & cleanSQL(it) & "'"  & "," after tRowData
>    get field "showID"
>    put "'" & cleanSQL(it) & "'" after tRowData
> 
> this does not
> 
> get field  
> "name1,phone,child,adult,total,credit,paymenttype,address,address1,addre
> ss2,email,seatNo,ticket,showID"
>    put it into tColData
>    repeat with i = to number of items in tColData
>      put "'" & cleanSQL(it) & "'" & "," after tRowData
>    end repeat

That's because you can't refer to fields that way. Also, "repeat for each"
in this instance is easier than "repeat with i". Try this (watch line
wraps):

put 
"name1,phone,child,adult,total,credit,paymenttype,address,address1,address2,
email,seatNo,ticket,showID" into tFieldNames
repeat for each item tField in tFieldNames
  put "'" & cleanSQL(field tField) & "'" & "," after tRowData
end repeat

HTH,

Ken Ray
Sons of Thunder Software
Web site: http://www.sonsothunder.com/
Email: kray at sonsothunder.com

PS: If 'field tField' doesn't work, use 'the text of field tField'... I'm
pretty sure the first works, but this is all off the top of my head...




More information about the use-livecode mailing list