Page 1 of 1

Narrow by key...should be simple, yes?

Posted: Sun Jan 01, 2012 4:55 pm
by teacherguy
I'm losing my mind (what's left of it)

I have a datagrid of terms and definitions, and I put the datagrid into an array. I want to perform a filter in the resulting array, but I want to limit the filtering to a particular key, "Term."

How do I do this?

Re: Narrow by key...should be simple, yes?

Posted: Sun Jan 01, 2012 9:50 pm
by dunbarx
I am no expert, but can "filter" work with arrays?

You can certainly get the dgText and do your thing since the data now resides in a normal variable, but maybe fails when working with the dgData (which is what I assume you meant by "putting the dataGrid into an array").

Craig Newman

Re: Narrow by key...should be simple, yes?

Posted: Sun Jan 01, 2012 9:51 pm
by dunbarx
Ignore duplicate

Re: Narrow by key...should be simple, yes?

Posted: Mon Jan 02, 2012 12:22 am
by teacherguy
I'm sure you're right Craig, I'm learning as I go. What I'm trying to do is filter results and then obtain the indexes for each of the results, so my thought was that I need to be going with dgData not dgText so I can refer back to the original datagrid where I got the info.

Am I making any sense?

Re: Narrow by key...should be simple, yes?

Posted: Mon Jan 02, 2012 7:26 pm
by mwieder
I'm getting a little lost in the mixed terminology here. If I've got this right (that's a long shot) you've got a set of key-value pairs stored in a datagrid. You'd like to limit the displayed data to just a single key and show the value associated with it. If that's the case, and you have the key-value pairs in an array as well, you can pick out the array element as

get myArray[tKey]

Are you dealing with multiple key values? In that case an array might not be the best format. A tab-separated list would allow you to use the filter command, as Craig suggested:

filter myList with tKey & "*"

will give you just the key-value pairs that start with the key you're interested in.

Re: Narrow by key...should be simple, yes?

Posted: Mon Jan 02, 2012 9:06 pm
by teacherguy
mwieder wrote:I'm getting a little lost in the mixed terminology here.
Sorry about that.
mwieder wrote:If I've got this right (that's a long shot) you've got a set of key-value pairs stored in a datagrid.
Correct
mwieder wrote:You'd like to limit the displayed data to just a single key and show the value associated with it.
Correct
mwieder wrote:If that's the case, and you have the key-value pairs in an array as well, you can pick out the array element as

get myArray[tKey]
Here is what I have tried:

Code: Select all

on stsSearchBox_Search pTextToFind
   put the dgText[true] of group id 159323 into myTermArray --keys are "Term" and "Definition"
   get myTermArray["Term"]
   put the result into justTheTerm --so far this produces an exact duplicate of myTermArray
   filter justTheTerm with ("*" & pTextToFind & "*")
   set the dgText[true] of group id 335805 to justTheTerm
end stsSearchBox_Search
~Brian

Re: Narrow by key...should be simple, yes?

Posted: Mon Jan 02, 2012 11:55 pm
by dunbarx
Brian.

I ran your script with a simple datagrid. It worked for me, though I had to lose the "true" parameter when I set the dgText. It seems either I do not understand what you really want, or you have several lines of code that don't do anything. What functionality is missing from:

Code: Select all

on stsSearchBox_Search pTextToFind
   put the dgText of group id 159323 into myTermArray --keys are "Term" and "Definition"
   filter justTheTerm with ("*" & pTextToFind & "*")
   set the dgText of group id 335805 to justTheTerm
end stsSearchBox_Search
And as Mark said, you can extract simple keys and their associated element directly from an array.

Craig Newman

Re: Narrow by key...should be simple, yes?

Posted: Tue Jan 03, 2012 3:53 am
by teacherguy
dunbarx wrote:Brian.

It seems either I do not understand what you really want, or you have several lines of code that don't do anything.
Well, I think we both know which is the issue there :D

Thanks for your help and patience. Between the time of my last post and yours I heard from Ken Ray, and I got things working. The thing I was trying to avoid was having the filter bring up words that existed in both the Term column and the definition column. Seems to be working ok.

Code: Select all

on stsSearchBox_Search pTextToFind
   put the dgText of group id 159323 into myTermArray --keys are "Term" and "Definition"
   split myTermArray by column
   put myTermArray[1] into justTheTerm
   filter justTheTerm with ("*" & pTextToFind & "*")
   set the dgText of group id 335805 to justTheTerm
end stsSearchBox_Search
Then, to take that result and track it to the original index in my datagrid I did the following (shuddering as I show you this, I'm sure it is incredibly inefficient):

Code: Select all

on addMe
   put the dghilitedlines of me into tLineSelected
   if tLineSelected is empty then 
      answer "please select a term"
      exit addMe
   else
      put the dgDataOfLine[tLineSelected] of group id 335805 into lineToFind
      put lineToFind["Term"] into wordToFind
      dispatch "FindIndex" to group id 159323 with "Term", wordToFind
      put the result into goCheckThis
      put the dghilitedlines of group id 8117 into grabTheLine
      if grabTheLine is empty then 
         answer "please select a rehearsal event for this term"
         exit addMe
      end if
   end if
   put empty into cellToAddTo
   dispatch function "GetDataOfLine" to group id 8117 with grabTheLine, "Terms" --get the numbers of the indexes stored in the dg
   put the result into cellToAddTo
   put goCheckThis&comma after cellToAddTo
   dispatch "SetDataOfLine" to group id 8117 with grabTheLine, "Terms", cellToAddTo 
   show button "Added" with visual dissolve fast
   hide button "Added" with visual dissolve slow
end addMe