At 1:48 PM -0700 7/16/2001, Troy Rollins wrote:
>Kevin Miller  wrote:
>
>> Using "repeat for each" will give you the performance you need to deal with
>> larger quantities of data:
>>
>> put keys(myArray) into listOfKeys
>> repeat for each line l in listOfKeys
>> if item 2 of l is keyToFind then
>>    put myArray[l] into newVariable
>>    exit repeat
>>  end if
>> end repeat
>
>Now, granted my knowledge is limited (but growing slowly), but this function
>looks like it will use the names of the keys - rather than the stored
>content. Is that right? Or, if not, is there a way to do what I originally
>described - searching for the content of one key, and then putting the value
>of the content of a related key into a new variable?

What it does is to look at the key of each element, and put the element's
content into the variable if the key matches what you want. Here's a
line-by-line, might be easier to understand:

>I have a matrixed array, let say it looks like this -
>Array[1,"key1"]
>Array[1,"key2"]
>Array[1,"key3"]
>Array[2,"key1"]
>Array[2,"key2"]
>Array[2,"key3"]

  put the keys of myArray into listOfKeys
  -- This gets the set of keys - that is, element names - of myArray
  -- and puts it into a variable, for easier handling. The keys function
  -- returns a set of keys, one key per line. For example, your original
  -- array would return this:
  --   1,key1
  --   1,key2
  --   1,key3
  --   2,key1
  --   2,key2
  --   2,key3
  repeat for each line thisKey in listOfKeys
    -- we go through the keys, one per line, since we need to check
    -- the key names to find one that matches:
    if item 2 of thisKey is keyToFind then
      -- Since this is a 2D array, each line of the keys has 2 items.
      -- We're looking at the second one, per your original question.
      put myArray[thisKey] into newVariable
      -- "myArray[thisKey]" is the contents of that array element.
      exit repeat
    end if
  end repeat

Looking back at your original message, I may not have understood the
question, though. The other interpretation I come up with is that you want
to search the contents rather than the keys, and return the contents of a
corresponding element of the array - with the same first key but a
different second key. Is that closer? You can do this with, hmmm...

  put the keys of myArray into listOfKeys
  repeat for each line thisKey in listOfKeys
    if item 2 of thisKey is "key2" then -- in the right column
      if myArray[thisKey] is whatToFind then -- found it in the contents
        put myArray[item 1 of thisKey,"key1"] into newVariable
        -- get the contents of the corresponding item of the key1 column
        exit repeat -- we found it, so stop
      end if
    end if
  end repeat

(This goes through all the elements of the array until it finds what it
wants, and is the general solution. You can get more efficient if the array
keys will always be numbers - might matter or not, depending on how large
the arrays are.)

--
Jeanne A. E. DeVoto ~ [EMAIL PROTECTED]
http://www.runrev.com/
Runtime Revolution Limited - Power to the Developer!


Reply via email to