Page 1 of 1

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

Posted: Wed Jul 01, 2015 8:26 pm
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

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

Posted: Wed Jul 01, 2015 9:10 pm
by dunbarx
Hi.

What is an "nr"?

Craig

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

Posted: Wed Jul 01, 2015 9:17 pm
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

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

Posted: Wed Jul 01, 2015 9:18 pm
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 :) )

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

Posted: Wed Jul 01, 2015 10:19 pm
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

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

Posted: Thu Jul 02, 2015 7:19 am
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

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

Posted: Thu Jul 02, 2015 12:08 pm
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