Getting a single column of a datagrid

Bob Sneidar bobs at twft.com
Mon Mar 21 20:18:04 EDT 2011


You may remember a while back my wanting a quick way to extract a single column of data from a datagrid without having to go through a repeat loop? Well if you use Trevor's sqlYoga, it comes with a neat little function called printkeys(). If you have it, try this trick: 

Let's say you have a datagrid called "myDatagrid" with 3 columns, columna, columnb, columnc. You just want columnc. 

-- get text of the array data
put the dgData of group "myDatagrid" into aArray
put printKeys(aArray) into theData -- now we have text

-- at this point you need to know the name of your column
filter theData with "*columnc: *" -- now just the columnc lines

-- isolate everything before the first value which is leading spaces, 
-- the column name, a colon and a trailing space, the same for all lines	
put word 2 of theData into theWord
put offset(theWord, theData) into firstChar

-- now let's delete everything before the values on each line	 
replace char 1 to firstChar - 1 of theData with empty in theData
put theData -- this is now just the data in columnc

It would be nice if printkeys() was public domain but I don't think it is. Still, sqlYoga is a good investment anyways. Heck I might have paid what he charges for sqlYoga just for that function! ;-)

Bob






More information about the Use-livecode mailing list