Returning the max number out of a column to a label field
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Returning the max number out of a column to a label field
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
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
Hi.
I always bring the information in a dataGrid into the clear before processing. The output will be tab and return delimited. Something like:
I do not know what you mean by " displaying a message in a label field of "Harry Reddy 1200". Please clarify.
Craig Newman
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
Craig Newman
Re: Returning the max number out of a column to a label fiel
Hi David,
1. welcome to the forum!
2. what Craig says!
Maybe you want something like this:
Best
Klaus
1. welcome to the forum!

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
Klaus
Re: Returning the max number out of a column to a label fiel
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
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
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
If you are simply placing theData into a label field, you do not need to re-assemble it by its items. You could simply:
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:
Craig
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
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