how to get data from a datagrid column to get highest number

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

Post Reply
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

how to get data from a datagrid column to get highest number

Post by sphere »

Hi,
i'm strugling to find the highest nr in a column.
The column represents the number of rows in the datagrid.
Now i used 2 simple commands and they give a number but it is less then the actual numbers in the column.
I've checked the lessons and tutorials but they seem to point only to get data from a row when clicked on.

I want a simple check to get the highest nr in the Number column, so i can add a new row in the database directly and then read it out again and put all info renewed in the datagrid.
So i know it is actually written into the database. (so this adding goes thru php scripts and is working, and yes i know it is possible to do this automatically via mysql statements) but then i can't see whats happening. I want ot be sure it gets the highest value avalable and add 1 to it.

it tried this:

Code: Select all

on mouseUp
   #get the dgNumberOfRecords of group "Datagrid 1"   ----this give 2157 while there are actually 2159 rows including row 0
   #get the dgNumberOfLines of group "Datagrid 1"      -----same as above
  #put "Number"into pColumns
   repeat for each line tLine in the dgColumn["Number"] of group "Datagrid 1"
  put GetDataOfIndex(the dgIndex of me, the dgColumn["Number"] of group "Datagrid 1") into theColumnValue
pput the last line of theColumnValue into field "test"
#answer it
end repeat
end mouseUp
any help will be appreciated.

Thanks!
Sphere
Last edited by sphere on Wed Jul 01, 2015 9:27 pm, edited 2 times in total.
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10509
Joined: Wed May 06, 2009 2:28 pm

Re: how to get data from a datagrid column to get the highes

Post by dunbarx »

Hi.

What is an "nr"?

Craig
SparkOut
Posts: 2989
Joined: Sun Sep 23, 2007 4:58 pm

Re: how to get data from a datagrid column to get the highes

Post by SparkOut »

Er, is that not a recognisable abbreviation for number over there?
I prefer nr myself, but no is still more common in Britland, but yeeps, divided by a common language we are. (Although this is a Continental* introduction

*European
Last edited by SparkOut on Wed Jul 01, 2015 9:22 pm, edited 3 times in total.
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: how to get data from a datagrid column to get the highes

Post by sphere »

dunbarx wrote: What is an "nr"?
Hi, yeah sorry changed it. It's short written nummers=nr's (numbers are nummers in Dutch).
(easy slips in when thinking how to write in English :) )
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: how to get data from a datagrid column to get highest nu

Post by sphere »

ok getting a bit further, thanks to pieces of lines Bangkok wrote somewhere in the forum

Code: Select all

on mouseUp
   put the dgText of group "Datagrid 1" into tMaster
   set itemdelimiter to tab
   put item 1 of line 1 of tMaster into tChunk
   answer tChunk
   
So this is giving me the number which is on row 1 first column

Code: Select all

on mouseUp
   put the dgText of group "Datagrid 1" into tMaster
   set itemdelimiter to tab
   repeat for each line tLine in tMaster
      add 1 to tLine
   put item 1 of line tLine into tChunk
   #answer tChunk
   put tChunk into field"test"
   end repeat
Something wrong here, this does do nothing

When this works i can search for the highest number
SparkOut
Posts: 2989
Joined: Sun Sep 23, 2007 4:58 pm

Re: how to get data from a datagrid column to get highest nu

Post by SparkOut »

sort lines of tMaster numeric descending by item <column number> of each

Then you can pick the column itrm from line 1 which will be the maximum value
sphere
Posts: 1145
Joined: Sat Sep 27, 2014 10:32 am

Re: how to get data from a datagrid column to get highest nu

Post by sphere »

Thanks, great idea!

I will test it tonight.

edit ----
this is the code that does the trick

Code: Select all

on mouseUp
   put the dgText of group "Datagrid 1" into tMaster
   set itemdelimiter to tab
   sort lines of tMaster numeric descending by item 1 of each
   put item 1 of line 1 of tMaster into tChunk
   answer tChunk
   end mouseUp
Thanks again Sparkout for your help :D
Post Reply