At 17:27 +0100 05/10/2002, Kevin McCarthy wrote:

>   checks=[\
>[A,0,0,0,0,0,0,D],\
>[0,0,0,0,0,0,0,0],\
>[0,0,0,0,0,0,0,0],\
>[0,0,C,0,0,B,0,0],\
>[0,0,0,0,0,0,0,0],\
>[0,0,0,0,0,0,0,0],\
>[0,0,0,0,0,0,0,0],\
>[0,0,0,0,0,0,0,0]]
>
>
>I have this checks array!, and I have the value A,B,C or D in it, and I
>need to find it's position in the list. I want it to return a value for
>C being [4][3]
>Can someone help me set up a routine to return this value...?

You'll probably want to do a pair of nested repeat loops. The first 
loop will cycle through the outer lists; the second loop, inside the 
first, will do its thing on the individual entries in the lists. If 
the second loop finds its term it kicks out and sets a flag to true 
to tell the outer loop to terminate its cycle as well. Something like 
this:

   on GetArrayPosition, sChar

     nAllLists = checks.count

     repeat with nFirstPos = 1 to nAllLists

       bFoundTerm = FALSE
       lSubList = checks[nFirstPos]
       nListTerms = lSubList.count

       repeat with nSecondPos = 1 to nListTerms

         if lSubList[nSecondPos] = sChar then
           bFoundTerm = TRUE
           exit repeat
         end if

       end repeat

       if bFoundTerm = TRUE then
         exit repeat
       end if

     end repeat

     if bFoundTerm = TRUE then
       return [ nFirstPos, nSecondPos ]
     else
       return [ 0, 0 ]
     end if

   END GetArrayPosition

You'd call it something like:

   put lIndexPos = GetArrayPosition( "c" )
   -- [4, 3]
   put lIndexPos = GetArrayPosition( "q" )
   -- [0, 0]

-- 

              Warren Ockrassa | http://www.nightwares.com/
  Director help | Free files | Sample chapters | Freelance | Consulting
        Author | Director 8.5 Shockwave Studio: A Beginner's Guide
                    Published by Osborne/McGraw-Hill
          http://www.osborne.com/indexes/beginners_guides.shtml
[To remove yourself from this list, or to change to digest mode, go to 
http://www.penworks.com/lingo-l.cgi  To post messages to the list, email 
[EMAIL PROTECTED]  (Problems, email [EMAIL PROTECTED]). Lingo-L is for 
learning and helping with programming Lingo.  Thanks!]

Reply via email to