Re: FindIndex question

2024-03-24 Thread Mike Kerner via use-livecode
just to sanitycheck myself, i opened 9.6.9, created a new stack, and added
a dg to it.
then i fired up the pb. expand the card, and you'll see the dg. there are
two behaviors assigned to the dg. the first is button id 1005 of stack
"revDataGridLibrary" which has, as its behavior, stack
"RevDataGridLibraryBehaviorsDataGridButtonBehavior"

On Sun, Mar 24, 2024 at 9:59 PM Mike Kerner 
wrote:

> it's in the behavior of the dg
> you can also go digging through the OSS repo, if you like.
>
>
> On Sun, Mar 24, 2024 at 5:23 PM Neville Smythe via use-livecode <
> use-livecode@lists.runrev.com> wrote:
>
>>
>> > On 25 Mar 2024, at 3:00 am,Mike Kerner wrote:
>> >
>> > i don't know if you dove into the code, but it's too early to think
>> about
>> > unpacking this, so  here's the code: ...
>>
>> Thanks Mike
>>
>> While I was aware of the optional parameters feature of LC commands I
>> have never used it I so was unfamiliar with the syntax. The penny had never
>> dropped that the parameter list for a command is just an array, so
>> evidently you can actually send an array instead of a comma delimited list
>>
>> Which means that you can send FindIndex a single parameter pKeyPairsA
>> which is an array with alternating colName,searchStr values
>>
>> Setting up such an array is not particularly convenient for coding
>> however. My workaround had been to use a custom function hack
>>
>> function myFindIndex pDataGrid, pKeyPairs
>>— pKeyPairs is a comma delimited list such as
>> “colname1,str1,colname2,str2,..”
>>
>> replace comma with quote & comma & quote in pKeyPairs
>> put “dispatch FindIndex to” && pDataGrid && “with” && quote &
>> pKeyPairs & quote into tCommandStr
>> do tCommandstr
>>put the result into tFoundIndex
>>...
>>
>> A much more elegant (if probably no faster) solution is
>>
>> function myFindIndex pDataGrid, pKeyPairs
>>— pKeyPairs is a comma delimited list such as
>> “colname1,str1,colname2,str2,..”
>>
>> set the columnDelimiter to comma
>> split pKeyPairs by column
>> dispatch “FindIndex" to pDataGrid with pKeyPairs
>>put the result into tFoundIndex
>>...
>>
>>
>> BTW, where did you find the source code for DataGrid handlers? I now see
>> how one could write a FindIndices function to return all indices rather
>> than just the first found … or even a general WHERE  search :-)
>>
>> Neville Smythe
>>
>>
>>
>>
>> ___
>> use-livecode mailing list
>> use-livecode@lists.runrev.com
>> Please visit this url to subscribe, unsubscribe and manage your
>> subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>>
>
>
> --
> On the first day, God created the heavens and the Earth
> On the second day, God created the oceans.
> On the third day, God put the animals on hold for a few hours,
>and did a little diving.
> And God said, "This is good."
>


-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: FindIndex question

2024-03-24 Thread Mike Kerner via use-livecode
it's in the behavior of the dg
you can also go digging through the OSS repo, if you like.


On Sun, Mar 24, 2024 at 5:23 PM Neville Smythe via use-livecode <
use-livecode@lists.runrev.com> wrote:

>
> > On 25 Mar 2024, at 3:00 am,Mike Kerner wrote:
> >
> > i don't know if you dove into the code, but it's too early to think about
> > unpacking this, so  here's the code: ...
>
> Thanks Mike
>
> While I was aware of the optional parameters feature of LC commands I have
> never used it I so was unfamiliar with the syntax. The penny had never
> dropped that the parameter list for a command is just an array, so
> evidently you can actually send an array instead of a comma delimited list
>
> Which means that you can send FindIndex a single parameter pKeyPairsA
> which is an array with alternating colName,searchStr values
>
> Setting up such an array is not particularly convenient for coding
> however. My workaround had been to use a custom function hack
>
> function myFindIndex pDataGrid, pKeyPairs
>— pKeyPairs is a comma delimited list such as
> “colname1,str1,colname2,str2,..”
>
> replace comma with quote & comma & quote in pKeyPairs
> put “dispatch FindIndex to” && pDataGrid && “with” && quote &
> pKeyPairs & quote into tCommandStr
> do tCommandstr
>put the result into tFoundIndex
>...
>
> A much more elegant (if probably no faster) solution is
>
> function myFindIndex pDataGrid, pKeyPairs
>— pKeyPairs is a comma delimited list such as
> “colname1,str1,colname2,str2,..”
>
> set the columnDelimiter to comma
> split pKeyPairs by column
> dispatch “FindIndex" to pDataGrid with pKeyPairs
>put the result into tFoundIndex
>...
>
>
> BTW, where did you find the source code for DataGrid handlers? I now see
> how one could write a FindIndices function to return all indices rather
> than just the first found … or even a general WHERE  search :-)
>
> Neville Smythe
>
>
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: FindIndex question

2024-03-24 Thread Neville Smythe via use-livecode

> On 25 Mar 2024, at 3:00 am,Mike Kerner wrote:
> 
> i don't know if you dove into the code, but it's too early to think about
> unpacking this, so  here's the code: ...

Thanks Mike

While I was aware of the optional parameters feature of LC commands I have 
never used it I so was unfamiliar with the syntax. The penny had never dropped 
that the parameter list for a command is just an array, so evidently you can 
actually send an array instead of a comma delimited list

Which means that you can send FindIndex a single parameter pKeyPairsA which is 
an array with alternating colName,searchStr values

Setting up such an array is not particularly convenient for coding however. My 
workaround had been to use a custom function hack

function myFindIndex pDataGrid, pKeyPairs
   — pKeyPairs is a comma delimited list such as 
“colname1,str1,colname2,str2,..”

replace comma with quote & comma & quote in pKeyPairs
put “dispatch FindIndex to” && pDataGrid && “with” && quote & pKeyPairs & 
quote into tCommandStr
do tCommandstr
   put the result into tFoundIndex
   ...

A much more elegant (if probably no faster) solution is

function myFindIndex pDataGrid, pKeyPairs
   — pKeyPairs is a comma delimited list such as 
“colname1,str1,colname2,str2,..”

set the columnDelimiter to comma
split pKeyPairs by column
dispatch “FindIndex" to pDataGrid with pKeyPairs
   put the result into tFoundIndex
   ...


BTW, where did you find the source code for DataGrid handlers? I now see how 
one could write a FindIndices function to return all indices rather than just 
the first found … or even a general WHERE  search :-)

Neville Smythe




___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


Re: FindIndex question

2024-03-24 Thread Mike Kerner via use-livecode
i don't know if you dove into the code, but it's too early to think about
unpacking this, so  here's the code:

*## pSearchA is array-valued index for accessing sDataArray*

*## pSearchA[1] = key_1*

*## pSearchA[2] = key_2*

*command* FindIndex pKeyIndexA, pSearchString *--, ...*

*-*

*local* foundAMatch, theFoundIndex

*local* i

*local* theIndex

*-*

*repeat* for each key theIndex in sDataArray

*## Developer can pass in multiple search strings to perform an AND search*

*repeat* with i = 1 to the paramCount step 2

*if* sDataArray[theIndex][param(i)] is param(i+1) *then*

*put* true into foundAMatch

*else*

*put* false into foundAMatch

*end* *if*

*## AND search didn't pan out. Move on to next index.*

*if* not foundAMatch *then* *exit* *repeat*

*end* *repeat*

*if* foundAMatch *then*

*put* theIndex into theFoundIndex

*exit* *repeat*

*end* *if*

*end* *repeat*

*return* max(0, theFoundIndex)

*end* FindIndex

On Sun, Mar 24, 2024 at 5:46 AM Neville Smythe via use-livecode <
use-livecode@lists.runrev.com> wrote:

> I am using FindIndex on a dataGrid
>
>  dispatch "FindIndex" to tDataGrid with pKey, pSearchingString
>
> and I can pass multiple pKey, pSearchingString pairs such as
> “col1",pSearchStr1,”col2”,pSearchStr2 as cited in the dictionary entry
>
> But there is also a rather cryptic note at the end of the FindIndex
> dictionary entry
>
>  Note that pKey can also be an array if you want to use array-valued
> array indexing to locate pSearchingString.
>
> I took that to mean one could set up an array pKey with values such as
> pKey[“col1”]=pSearchStr1,  pKey[“col2”]=pSearchStr2
> and then just pass the pKey array. But that doesn’t work.
>
> Neither does using two indexed arrays pKey and pSearchStr with
> pKey[1]=“col1”, pSearchStr[1]=pSearchStr1,pKey[2]=“col2”,
> pSearchStr[2]=pSearchStr2
>
> Anyone know what it does mean?
>
>
> Neville Smythe
>
>
>
>
> ___
> use-livecode mailing list
> use-livecode@lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>


-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
   and did a little diving.
And God said, "This is good."
___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode


FindIndex question

2024-03-24 Thread Neville Smythe via use-livecode
I am using FindIndex on a dataGrid

 dispatch "FindIndex" to tDataGrid with pKey, pSearchingString

and I can pass multiple pKey, pSearchingString pairs such as 
“col1",pSearchStr1,”col2”,pSearchStr2 as cited in the dictionary entry

But there is also a rather cryptic note at the end of the FindIndex dictionary 
entry

 Note that pKey can also be an array if you want to use array-valued array 
indexing to locate pSearchingString.

I took that to mean one could set up an array pKey with values such as  
pKey[“col1”]=pSearchStr1,  pKey[“col2”]=pSearchStr2
and then just pass the pKey array. But that doesn’t work. 

Neither does using two indexed arrays pKey and pSearchStr with  pKey[1]=“col1”, 
pSearchStr[1]=pSearchStr1,pKey[2]=“col2”, pSearchStr[2]=pSearchStr2
 
Anyone know what it does mean?


Neville Smythe




___
use-livecode mailing list
use-livecode@lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription 
preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode