Hello I’ve found this bit of code that check if an item is in a list…
set theList to {"a", "b", "c", "d"}
set whatImLookingfor to "c"
if whatImLookingfor is in theList(value) then
display alert "Yes" giving up after 1
else
display alert "No" giving up after 1
end if
but can someone tell me how to check for an item in a record?
set theList to {{letter:"a", value:1}, {letter:"b", value:2}, {letter:"c", value:3}, {letter:"d", value:4}}
set whatImLookingfor to "c"
if whatImLookingfor is in theList(letter) then -- this is the bit I'm not sure ha to reference!
display alert "Yes" giving up after 1
else
display alert "No" giving up after 1
end if
Thanks
LJ
Hi,
your first script can’t work: theList(value) is a handler call with parameter value,
but there is no handler theList and no variable value defined
set theList to {"a", "b", "c", "d"}
set whatImLookingfor to "c"
if whatImLookingfor is in theList then
display alert "Yes" giving up after 1
else
display alert "No" giving up after 1
end if
you can parse a list of records only with a repeat loop
set theList to {{letter:"a", value:1}, {letter:"b", value:2}, {letter:"c", value:3}, {letter:"d", value:4}}
set whatImLookingfor to "c"
set flag to false
repeat with i in theList
if i's letter is whatImLookingfor then
set flag to true
exit repeat
end if
end repeat
if flag then -- this is the bit I'm not sure ha to reference!
display alert "Yes" giving up after 1
else
display alert "No" giving up after 1
end if
Hi Stefan
Thanks for your reply, your right I should have removed the (value) from the first script.
Cool, that repeat loop work great!
thanks again.
LJ