Routine works once, second loop fails!

Hello, I’m having this problem, when I execute this code


on run
	tell application "Finder"
		set the Enclosing_Folder to my Get_Me()  -- What would be the easy way of getting the enclosing folder where the app is placed? -- Tried enclosing, containing.
		set the File_List to (every file of Enclosing_Folder whose name extension contains "txt")
	end tell
	repeat with This_File in File_List
		display dialog (name of This_File) as string -- just for check
		set This_File to This_File as alias
		set Propiedades to my Process_File(This_File) -- gets fields from ".txt" template I wrote to add someone to the "Address Book"

		my New_Item(Propiedades) -- add's a person to "Address Book" acording to the info collected by Process_File()

		activate -- returning from (tell app "Address Book"), regaining control
		display dialog ("Finished: " & This_File) as string -- just for check
	end repeat
end run

The thing is that New_Item() works fine the first time, but returns:

the second time, when processing the next file. Why? It’s as if once the script uses the subroutine it trows it away and forgets about it!

Another thing not working is:


tell app "Address Book"
	set birth date of person "XX" to "dd/mm/yyyy" -- should it be "mm/dd/yyyy"? My system configuration is as I typed it first. Tried them all though ...
	-- first name, last name, note, organization all work, but not birth date (which is a direct property of the class person). How do I activate it?
end tell

I’m running OS 10.3
Ok, I thing that’s it for now! Thank’s a lot!

Hi, Nikel.

The most likely reason for handler problem is that you’ve got a variable with the same name (New_Item) somewhere else in the script. Handler names are global variables, so using an expression like ‘set New_Item to some_value’ will cause the script to try to run ‘some_value’ next time rather than the handler!

That should be:

tell app "Address Book"
   set birth date of person "XX" to date "dd/mm/yyyy"

The property ‘birth date’ has to be set to an AppleScript date object. An expression like “10/06/2004” - is just a string. By putting the keyword ‘date’ in front of it, you form a date specifier.