dynamic date creation problem

im trying to created a date like so:


set content of control "dueDate" to date "Monday, September 19, 2005 12:00:00 AM"

this works, however when I do this


set myDate to "Monday, September 19, 2005 12:00:00 AM"
set content of control "dueDate" to date myDate

i get an error:

Can't make date "Monday, September 19, 2005 12:00:00 AM" of «class taVI» id 16 of «class tabV» id 15 of window id 1 into type anything. (-1700)

I really need to create my dates dynamically, any idea what the problem could be?

From the error message, it looks as though you have to resolve ‘date myDate’ before using it.

set myDate to "Monday, September 19, 2005 12:00:00 AM"
set myDate to date myDate
set content of control "dueDate" to myDate

-- Or:
set myDate to "Monday, September 19, 2005 12:00:00 AM"
set content of control "dueDate" to (get date myDate)

Hi,
thanks
this doenst work:


set myDate to "Monday, September 19, 2005 12:00:00 AM"
set content of control "dueDate" to (get date myDate)

this does:


set content of control "dueDate" to (get date "Monday, September 19, 2005 12:00:00 AM")

i dont get it!!!

In your first example, ‘date myDate’ is an instruction to create a date object when the script actually runs. In the second example, the date object’s compiled directly into the script.

Looking at your code more closely, it seems it must be inside nested ‘tell’ blocks. If so, you’re telling the item that contains the element ‘control “dueDate”’ to create the date object, which it probably doesn’t know how to do. (It may think the ‘date’ keyword is supposed to represent another of its elements.) If it’s possible in your script to create the date before the ‘tell’ blocks start, that should work. Otherwise you could try:

set myDate to "Monday, September 19, 2005 12:00:00 AM"
tell me to set myDate to date myDate
set content of control "dueDate" to myDate

-- Or possibly:
set myDate to "Monday, September 19, 2005 12:00:00 AM"
set content of control "dueDate" to (my date myDate)

Failing that, you could put the date creation into a separate handler:

set myDate to "Monday, September 19, 2005 12:00:00 AM"
set content of control "dueDate" to (my makeDate(myDate))

-- blah blah blah

on makeDate(theDate)
	return date theDate
end makeDate

One of those should do it. :slight_smile:

Thanks so much, this was driving me nuts.