Hi,

Sorry if this jump in seems impolite. I am a newbie here and haven't gone
through the FAQ yet. (Would someone please point me to it?)

I do remember that Director provides a getPos(inputList, searchItem)
function for linear or property lists which return the first position of the
"inputList" element that matches the "searchItem" or 0 when it finds no
match. This function is case sensitive.

So maybe instead of stepping through the list ourseleves, we can just let
the underlying C or Assembly code does it for us, as in following handler.


on addItem theList, theItem
  if not ilk(theList, #linearList) then exit
  itemPos = theList.getPos(theItem)
  if itemPos then return itemPos
  theList.add(theItem)
  return theList.getPos(theItem)
end


Hope this might help and sorry again if it's rude or something to just jump
right in.


Thomas YEH





on 12/12/00 1:07 AM, John Erazo at [EMAIL PROTECTED] wrote:

> From: "Kerry Thompson" <[EMAIL PROTECTED]>
> Sent: Tuesday, December 12, 2000 1:28 PM
> 
>> John, this line is your problem. You're setting inItem to the value of
>> gList[i]. Try this:
>> 
>> global gList
>> 
>> on addItem inItem
>> totalCount = gList.count
>> repeat with i = 1 to totalCount
>> if gList[i] = inItem then
>> alert "Item already exists."
>> return VOID
>> else
>> gList.add(inItem)
>> -- take out the exit repeat
>> end if
>> end repeat
>> end
> 
> I didn't realized that I was really *putting*
> values to inItem because I never used
> the command set.  Very clever !!!
> 
> I tried this in the Message window..
> 
> -- Welcome to Director --
> 
> put gList
> -- ["Earth", "Jupiter", "Mars", "Venus", "Saturn"]
> 
> set inItem = "Jupiter"
> 
> put inItem = gList[2]
> -- 1
> 
> put inItem = gList[3]
> -- 0
> 
> 
> Thanks again for all the help.
> 
> cheers,
> John Erazo
> 
> 
> 
> [To remove yourself from this list, or to change to digest mode, go to
> http://www.penworks.com/LUJ/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!]
> 


[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/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