Page 1 of 1

dispatch "FindIndex" Question

Posted: Tue Feb 18, 2014 11:26 pm
by lohill
If i use 'dispatch "FindIndex" to group "DataGrid 1" with "message", "hi"' and there are in the datagrid multiple rows where the "message" column contains "hi", what should I expect to find in 'the result'?

Larry

Re: dispatch "FindIndex" Question

Posted: Wed Feb 19, 2014 1:34 pm
by Klaus
Hi Larry,

"The silence of the docs" :D

I have no idea but would exspect the FIRST found index with "hi" in column "message".
Can't you just make a little test? 8)



Best

Klaus

Re: dispatch "FindIndex" Question

Posted: Thu Feb 20, 2014 12:32 am
by Zryip TheSlug
Hi Larry and Klaus,
I have no idea but would exspect the FIRST found index with "hi" in column "message".
That is correct.

Re: dispatch "FindIndex" Question

Posted: Thu Feb 20, 2014 1:49 am
by lohill
If that is the case then how would you find a second or third occurrence of 'hi' if they were to exist? It was my hope that someone would say you would get a comma delimited list of all such occurrences but that was not what I was seeing. This then begs the question 'if it finds the first how might that be affected by which column and which direction the sort was?'

Larry

Re: dispatch "FindIndex" Question

Posted: Thu Feb 20, 2014 11:31 pm
by Zryip TheSlug
Hi Larry,
lohill wrote:If that is the case then how would you find a second or third occurrence of 'hi' if they were to exist? It was my hope that someone would say you would get a comma delimited list of all such occurrences but that was not what I was seeing. This then begs the question 'if it finds the first how might that be affected by which column and which direction the sort was?'
For getting a list of indexes, you have to write your own FindIndex command.

Here is my implementation of the FindIndex command:

Code: Select all

command dgh_FindIndexes pWhichDataGrid, pTheKey, pSearchType, pSearchString
   local sDataArray, foundAMatch, theFoundIndex, theIndex, tIndexValue, tNotSearch, tTheResult
   
   put the dgData of pWhichDataGrid into sDataArray
   
   if (first word of pSearchType is "not") then
      put "not " into tNotSearch
      delete first word of pSearchType
   else
      put empty into tNotSearch
   end if
   
   repeat for each key theIndex in sDataArray
      put sDataArray[theIndex][pTheKey] into tIndexValue
      
      put value(tNotSearch & "(" & quote & tIndexValue & quote && pSearchType && quote & pSearchString & quote & ")") into foundAMatch
      
      if foundAMatch then
         put theIndex into item (number of items of theFoundIndex + 1) of theFoundIndex
      end if
   end repeat
   
   if (theFoundIndex is empty) then
      put 0 into tTheResult
   else
      put theFoundIndex into tTheResult
   end if
   
   return tTheResult
end dgh_FindIndexes

1. pWhichDataGrid is the long id of a datagrid group

2. pTheKey is a column name

3. pSearchType accepts one of the following operators:
  • - is / is not
    - begins with / not begins with
    - ends with / not ends with
    - contains / not contains
    - = / > / < / >= / <= / <>
4. pSearchString is the value to find in the datagrid rows


Example:

Code: Select all

dgh_FindIndexes the long id of grp "myDatagrid", "message", "is", "hi"
set the dgHilitedIndexes of grp "myDatagrid" to the result

Best,

Re: dispatch "FindIndex" Question

Posted: Sat Feb 22, 2014 1:06 am
by lohill
Thanks TheSlug,

This is beautiful. If I can 'digest' it, it is going to be very helpful.

Larry

Re: dispatch "FindIndex" Question

Posted: Sat Feb 22, 2014 1:57 am
by lohill
Works like a charm! Thanks again.

Larry