List Trouble

Hello,

I have no idea why I can;t get this little piece of script to work. All it’s supposed to do is go through the list and when the variable matches display the value.

It seems so easy and yet I can;t get it to work.

Thanks
Dallas


set d to "9:02 PM"

set t_time to {"9:00 PM", "9:01 PM", "9:02 PM"}

repeat with f in t_time
	if f is equal to d then
		display dialog f
	end if
end repeat

Dallas:

The form of the repeat you have chosen uses a reference the value in the list, not the value itself. Therefore, your if/then analysis will always be false. By changing the syntax a little to this:


set d to "9:02 PM"

set t_time to {"9:00 PM", "9:01 PM", "9:02 PM"}

repeat with f in t_time
	if (contents of f) is equal to d then
		display dialog f
	end if
end repeat

You are now comparing the actual value that the variable f is referencing, and you get the true statement when you find the proper equivalent.

Thank you Craig. Another lesson learned.
Dallas