dispatch "FindIndex" Question

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

dispatch "FindIndex" Question

Post by lohill » Tue Feb 18, 2014 11:26 pm

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

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

Re: dispatch "FindIndex" Question

Post by Klaus » Wed Feb 19, 2014 1:34 pm

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

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: dispatch "FindIndex" Question

Post by Zryip TheSlug » Thu Feb 20, 2014 12:32 am

Hi Larry and Klaus,
I have no idea but would exspect the FIRST found index with "hi" in column "message".
That is correct.
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: dispatch "FindIndex" Question

Post by lohill » Thu Feb 20, 2014 1:49 am

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

Zryip TheSlug
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 163
Joined: Tue Jan 26, 2010 10:15 pm
Contact:

Re: dispatch "FindIndex" Question

Post by Zryip TheSlug » Thu Feb 20, 2014 11:31 pm

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,
TheSlug
http://www.aslugontheroad.com - Tutorials, demo stacks and plugins for LiveCode
Data Grid Helper - An intuitive interface for building LiveCode's Data Grids
Excel Library- Extends the LiveCode language for controlling MS Excel

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: dispatch "FindIndex" Question

Post by lohill » Sat Feb 22, 2014 1:06 am

Thanks TheSlug,

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

Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: dispatch "FindIndex" Question

Post by lohill » Sat Feb 22, 2014 1:57 am

Works like a charm! Thanks again.

Larry

Post Reply