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

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Davidng
Posts: 4
Joined: Tue Sep 15, 2015 8:46 am

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

Post by Davidng » Tue Sep 15, 2015 9:10 am

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Tue Sep 15, 2015 2:08 pm

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

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

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

Post by Klaus » Tue Sep 15, 2015 2:44 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Tue Sep 15, 2015 3:53 pm

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

Davidng
Posts: 4
Joined: Tue Sep 15, 2015 8:46 am

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

Post by Davidng » Tue Sep 15, 2015 5:48 pm

Thank you all, Klaus your solution worked perfectly! Fortunately I didn't need to put the information back in the DG.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

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

Post by dunbarx » Tue Sep 15, 2015 7:55 pm

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

Post Reply