PDA

View Full Version : Can't make type into string - variable question




hamw
Nov 7, 2010, 05:19 PM
Hi,

I am trying to write a relatively simple applescript with a transfer of one variable value to another as follows:


set value of variable "Button_1" to value of variable "Preset_1" as string



The variable value is a word, Guitar, not a number. The compiler keeps coming back and saying that it "can't make variable "Preset_1" into type string". I've tried setting the value to a system variable as follows:



set Button_1a to value of variable "Preset_1"
set value of variable "Button_1" to value of variable Button_1a


same error, still doesn't work. Any ideas?



HiRez
Nov 7, 2010, 06:48 PM
You've got some weird syntax there and it's hard to tell what you're trying to do. The names of variables (as opposed to the value of a string assigned to a variable) are not enclosed in quotes, and you don't need to type the word "variable". Normally you just assign variables with a more simple syntax, like this:

set a to "Value A"
set b to a
-- [The variable named] b now contains [the string] "Value A"

Is Button_1 the name of a variable, or an interface object (an actual button)? If you post the entire code where you assign variables it might help. You only need to use "as string" if it's not already a string, to coerce it into a string type from another type.

hamw
Nov 8, 2010, 08:45 AM
Oops. Turned out I had an extra _ in one of the variables. Thanks!