i am having a problem formating a date command.
set currentDate to date to the contents of text field "timeTextfield"
i get the error “Can’t get date of “01:00:00”. (-1728)”
any suggestions?
i am having a problem formating a date command.
set currentDate to date to the contents of text field "timeTextfield"
i get the error “Can’t get date of “01:00:00”. (-1728)”
any suggestions?
You can try:
Jon
thanks jon for the tip. but now i get a NSCannotCreateScriptCommandError… arg. i hate those.
property currentDate : 0
property startDate : 0
property endDate : 0
set currentDate to (contents of text field "timeTextfield") as date
set startDate to current date
set endDate to startDate + (time of currentDate)
this input date is in the following format. HH:MM:SS (00:00:00)
it looks to me the trouble is still with the
set currentDate to (contents of text field "timeTextfield") as date
it is frustrating. everything else works. but that one line.
-Dan
the only documentation that i can find of accepting date / times from a textfield, comes from a display dialog, and not from a panel window. i have tried the display dialog, and it works great… but i have more then one textfield to submit.
set currentDate to date (text returned of withReply)
This works for me (assuming you have this in the proper tell block of the container of the text field, i.e., “tell window 1”):
Jon
i have narrowed my error to “set currentDate to date currentDate”
i get the “NSCannotCreateScriptCommandError (10)” Applescript error.
i have read apple’s error pages. doesn’t do much to help me resolve it. not even really sure why it is giving that error at the line of code, but it does. according to everything i have read, the line is correct.
on clicked theObject
if name of theObject is "setButton" then
tell window of theObject
set theProgram to contents of text field "programTextfield"
set theTime to contents of text field "timeTextfield"
set theDate to theTime as string
set currentDate to date theDate -- NS error occurs here.
end tell
try
set the contents of text field "displayTextfield" of window "mainWindow" to theProgram
set the contents of text field "timerTextfield" of window "mainWindow" to currentDate
set needs display of text field "displayTextfield" of window "mainWindow" to true
set needs display of text field "timerTextfield" of window "mainWindow" to true
end try
end if
end clicked
i would think that i am using the correct tell blocks? should i be using a different tell?
Hi
I am not sure that this is solution of your problem there (I knows little ASStudio), but I have already met this problem when the function “date” was inside a statement “tell - end tell”. The solution that I had found was to use the function date in a dedicated sub-routine, here is an idea:
on clicked theObject
if name of theObject is "setButton" then
tell window of theObject
set theProgram to contents of text field "programTextfield"
set theTime to contents of text field "timeTextfield"
set theDate to theTime as string
set currentDate to my SubDate(theDate)
end tell
try
set the contents of text field "displayTextfield" of window "mainWindow" to theProgram
set the contents of text field "timerTextfield" of window "mainWindow" to currentDate
set needs display of text field "displayTextfield" of window "mainWindow" to true
set needs display of text field "timerTextfield" of window "mainWindow" to true
end try
end if
end clicked
on SubDate(TheString)
return (date TheString) as date
end SubDate
… :rolleyes:
thanks fredo! that worked great! no more nasty errors.
to make a timer count down from a pre set time… once would use code something close to this? I can’t get it to update the timer window correctly.
property countdown : false
on idle theObject
if countdown is true then
if (current date) is greater than endDate then
set countdown to false
tell application theProgram to quit
set the contents of text field "displayTextfield" of window "mainWindow" to "Time is up!"
set needs display of text field "displayTextfield" of window "mainWindow" to true
else
set elapsedTime to (current date) - startDate
set contents of text field "timerTextfield" of window "mainWindow" to currentDate - elapsedTime
end if
end if
return 1
end idle
this is where i set all the info, that works great.
property currentDate : 0
property startDate : 0
property endDate : 0
on clicked theObject
if name of theObject is "setButton" then
tell window of theObject
set theProgram to contents of text field "programTextfield"
set theTime to contents of text field "timeTextfield"
set theDate to theTime as string
set currentDate to my SubDate(theDate)
set startDate to current date
set endDate to startDate + (time of currentDate)
set countdown to true
end tell
try
set the contents of text field "displayTextfield" of window "mainWindow" to theProgram
set needs display of text field "displayTextfield" of window "mainWindow" to true
end try
end if
end clicked