Page 1 of 1

Returning the max number out of a column to a label field

Posted: Tue Sep 15, 2015 9:10 am
by Davidng
Hi,

I am a complete newby to Livecode 7, and I am trying implement the following:

I have a data grid already populated with data. I have used comma's to indicate the separate columns in the data grid in the example below:

Name,Surname,Amount Owed
John,Smith,500
Amber,Britnay,1000
Harry,Reddy,1200

I need help with the script when clicking a button to search for the max amount in the "amount owed" column and displaying a message in a label field of "Harry Reddy 1200".

Thanks,
D

Re: Returning the max number out of a column to a label fiel

Posted: Tue Sep 15, 2015 2:08 pm
by dunbarx
Hi.

I always bring the information in a dataGrid into the clear before processing. The output will be tab and return delimited. Something like:

Code: Select all

on mouseUp
   set the itemDel to tab
   get the dgText of grp "yourDataGrid"
   sort it numeric by item 3 of each
   answer the last line of it
end mouseUp
I do not know what you mean by " displaying a message in a label field of "Harry Reddy 1200". Please clarify.

Craig Newman

Re: Returning the max number out of a column to a label fiel

Posted: Tue Sep 15, 2015 2:44 pm
by Klaus
Hi David,

1. welcome to the forum! :D
2. what Craig says!

Maybe you want something like this:

Code: Select all

on mouseUp
   set the itemDel to tab
   get the dgText of grp "yourDataGrid"
   sort it numeric by item 3 of each
   put last line of it into theData
   put item 1 of theData && item 2 of theData && item 3 of theData into fld "your LABEL field here"
end mouseUp
Best

Klaus

Re: Returning the max number out of a column to a label fiel

Posted: Tue Sep 15, 2015 3:53 pm
by dunbarx
Klaus.

I get the feeling the OP wants to load something back into the DG itself, in the row occupied by the "Harry Reddy..." info. But I could be wrong. So, David?

Craig

Re: Returning the max number out of a column to a label fiel

Posted: Tue Sep 15, 2015 5:48 pm
by Davidng
Thank you all, Klaus your solution worked perfectly! Fortunately I didn't need to put the information back in the DG.

Re: Returning the max number out of a column to a label fiel

Posted: Tue Sep 15, 2015 7:55 pm
by dunbarx
If you are simply placing theData into a label field, you do not need to re-assemble it by its items. You could simply:

Code: Select all

on mouseUp
   set the itemDel to tab
   get the dgText of grp "yourDataGrid"
   sort it numeric by item 3 of each
   put the last line of it into fld "your LABEL field here"
end mouseUp
But if you wanted to place it into an excel spreadsheet, or a table field in LC, where tabs delimit the various records, then you need to do this:

Code: Select all

on mouseUp
   set the itemDel to tab
   get the dgText of grp "yourDataGrid"
   sort it numeric by item 3 of each
   put last line of it into theData
   put item 1 of theData & tab & item 2 of theData & tab & item 3 of theData into fld "your TABLE Field"
end mouseUp
Craig