NSCannotCreateScriptCommandError (10) text field problem

Hey all, I’m fairly new to apple script studio and I’m getting an NSCannotCreateScriptCommandError (10) error with the following code:



on clicked object 
	set theAmount to 1
	set theEuros to 1
	set theRate to 1.1253
		
	set the contents of the text field "dollars" to theAmount as number -- <-- Problem is here
	

	
end clicked

This is a simple currency converter app using a rate*originalValue=result formula, although the rest of the code is not here for debugging purposes. The error is in the “set the contents” lline. I apologize if I seem incredibly n00b like, but I am quite new to the apple script. :smiley: Any help is greatly appreciated. Thanks in advance.

You are failing to reference the window that the text field is in. Try the following instead… where ‘myWindow’ is the name of your window:

set content of text field "dollars" of window "myWindow" to (theAmount as number)

I prefer to set the ‘content’ of objects, rather than ‘contents’… as some objects do not use the contents property as you may expect. For some objects, ‘contents’ returns a reference to the object itself, rather than the actual string or value in the object, so I consider it best to get in the habit of just using ‘content’ for everything (unless of course you have a good reason not to :wink: ).

Good luck,
j