Getting Contents of Multiple fields in order (Left-to-Right&Down)

Jim Ault jimaultwins at yahoo.com
Sat Jan 29 07:12:22 EST 2011


Assuming all fields on a card are the target fields to sort and combine

on sortFlds
    repeat with k = 1 to the number of fields
       put the rect of field k after fieldList
       put comma & k after fieldList
       put cr after fieldList
    end repeat
    sort fieldList numeric by item 2 of each -- Y
    sort fieldList numeric by item 1 of each -- X

    repeat for each line LNN in fieldList
       put fld (item 5 of LNN) after tWholeenchilada
       put cr after tWholeenchilada
    end repeat
    put tWholeenchilada into msg box
end sortFlds

--  in the second repeat loop you could use ...
--  put item 5 of LNN into fldNum
--  put fld fldNum after tWholeenchilada

Hope this helps.

On Jan 28, 2011, at 9:17 PM, John Patten wrote:
>
> I have a card with four fields. The field can be dragged around by  
> the user. I want to get the contents of each field and put them all  
> in one container.
>
> My attempt is below. I attempted to sort the list of fld locations  
> but that is susceptible to the y coordinate being above the previous  
> field and throwing off the sort.
>
> Here is what I tried:
>
> on mouseUp
> -- sort item 1 of the field locations
>   put 1 into x
>   put 2 into y
>   put the number of lines in cd fld "data" into tCount
>   repeat for tCount-1
>      put item x of line x of cd fld "data" into tFirstTest
>      put item x of line y of cd fld "data" into tSecondTest
>      if tFirstTest > tSecondTest then
>         put line y of cd fld "data" & return after cd fld "sortedData"
>         delete line y of cd fld "data"
>      else
>         put line x of cd fld "data" & return after cd fld "sortedData"
>         delete line x of cd fld "data"
>         end if
>      end repeat
>      put line 1 of cd fld "data" after cd fld "sortedData"
>      delete line 1 of cd fld "data"
>
>
> -- sort item 2 of the fld locations
>      put 1 into x
>      put 2 into y
>      put the number of lines in cd fld "sortedData" into tCount
>      repeat for tCount-1
>      put item y of line x of cd fld "sorteddata" into tFirstTest
>      put item y of line y of cd fld "sorteddata" into tSecondTest
>      if tFirstTest > tSecondTest then
>         put line y of cd fld "sorteddata" & return after cd fld "Data"
>         delete line y of cd fld "sorteddata"
>      else
>         put line x of cd fld "sorteddata" & return after cd fld "Data"
>         delete line x of cd fld "sorteddata"
>         end if
>      end repeat
>      put line 1 of cd fld "sorteddata" after cd fld "Data"
>      delete line 1 of cd fld "sorteddata"
>
>
> --put the field contents in the user's order
>      put the number of lines in cd fld "data" into tCount
>      put 1 into x
>     repeat tCount
>         put item 3 of line x of cd fld "data" into tTargetField
>         put cd fld tTargetField of group "theFields" & " " after  
> tWholeenchilada
>         add 1 to x
>      end repeat
>      put tWholeenchilada
> end mouseUp
>

Jim Ault
Las Vegas






More information about the use-livecode mailing list