I’m having a problem with an AS application I made in Jaguar with AS Studio. The application compiled and ran fine in Jaguar. However, when I switched to Panther, it began giving me an error. I have identified the lines that are causing the problem but can’t figure out what’s wrong.
The app is a dialog that launches and prompts the user for input which it then saves to a text file. The dialog uses editable text fields and pull down menus to gather user input. The problem comes in resetting the fields after the user clicks OK. The rest of the thing works fine: the dialog launches, the user can enter text, and the text is stored to a text file. But when it comes to resetting the fields to their original values, I get an error. The offending section of code follows. I get an error after it resets the first field “Job_Num” --which it does sucessfully. By the way, “Job_Num” is a plain editable text field, “time_amount” is a pull down menu with four values, “task_name” is a pull down menu something like 6 or 8 values and “notes” is a plain editable text field.
I think my problem is in the syntax of setting the contents of the pull-down menu fields to empty. I am setting them to “null” because that’s what worked in Jaguar but maybe the syntax has changed. Any ideas?
try
set contents of text field “Job_Num” of theWindow to “”
set contents of text field “time_amount” of theWindow to null
set contents of text field “task_name” of theWindow to null
set contents of text field “notes” of theWindow to “”
set TimeCounter to (TimeCounter + TimeLength) as number
set contents of text field “time_count” of theWindow to TimeCounter as text
on error
display dialog “error in resets”
end try
Why not just set the contents of the text field to “”, like the other fields in the code? I haven’t had much luck with ‘null’ as it seems to be lightly supported in applescript. You can use ‘missing value’, or even better use an empty string (“”) as it is easier for applescript to coerce this into other class values if needed.
Try this code…
try
set contents of text field "Job_Num" of theWindow to ""
set contents of text field "time_amount" of theWindow to ""
set contents of text field "task_name" of theWindow to ""
set contents of text field "notes" of theWindow to ""
set TimeCounter to (TimeCounter + TimeLength) as number
set contents of text field "time_count" of theWindow to TimeCounter as text
on error
display dialog "error in resets"
end try
Sorry, I read your code and did not also thoroughly read your post. You’re in the wrong forum, that’s why I didn’t pay attention to the details.
You’ve got your menu items referenced as text fields. I’m not clear on whether you want to reset the menu back to the first item, rename the menu items, or delete the menu items altogether. If you want to set the menu back to the default first value you use…
tell window "theWindow"
(* Set the current menu item to the first item *)
set current menu item of popup button "theButton" to menu item 1 of popup button "theButton"
(* Change the title of a button *)
set title of menu item "theMenuItem" of popup button "theButton" to "NewTitle"
(* Delete one item by name *)
delete menu item "theUnwantedItem" of popup button "theButton"
(* Delete all items; you always need at least one item in the menu *)
delete every menu item of popup button "theButton"
make new menu item at the end of menu items of popup button "theButton" with properties {title:"New Menu Title", tag:0, name:"MenuTitle",enabled:true}
end tell
Thanks. I still couldn’t manage to reset the pull-down menu’s to their first item. So I decided to cop out and not reset those pull downs at only, only the text ones. It’s a cop out but it moves me forward.
Any idea why the commented-out lines below won’t run?
tell window “theWindow”
set contents of text field “Job_Num” of theWindow to “”
set TimeCounter to (TimeCounter + TimeLength) as number
set contents of text field “time_count” of theWindow to TimeCounter as text
set contents of text field “notes” of theWindow to “”
–set current menu item of popup button “time_amount” to menu item 1 of popup button “time_amount”
– set current menu item of popup button “Task_Name” to menu item 1 of popup button “Task_Name”
end tell
tell window "theWindow"
set current menu item of popup button "theButton" to menu item 1 of popup button "theButton"
set current menu item of popup button "theButton" to menu item "theFirstMenuItem" of popup button "theButton"
end tell
Make sure your buttons’ names are correctly referenced, and that they’re not in another container object like a box or tab view. Otherwise, it might be corrupted, because there’s not a lot else to do wrong in this case. Good luck…
j