As far as I know, AppleScript can’t convert a text string to a variable. It’ll keep telling you access not allowed because the compiler thinks you want X4 itself to become 93.
tell application "Microsoft Excel"
set mySize to 10
set myCell to range "B1"
set myList to {}
repeat with i from 1 to mySize
copy (value of (get offset myCell row offset (i - 1)) as integer) to end of myList
end repeat
myList
end tell
The Excel details of how you loop through the range would depend on what range you are given.
But in general, a list with 10 elements is easier to work with than the 10 variables x1,x2,x3,…,x10.
tell application "Microsoft Excel"
set mySize to 10
set myCell to range "B1"
set myList to {}
set theString to ""
set counter to 0
repeat with i from 1 to mySize
set counter to counter + 1
set theItem to (value of (get offset myCell row offset (i - 1) as integer))
if counter is equal to mySize then
set theRecord to ("variable_" & counter as text) & ":" & "\"" & theItem & "\""
else
set theRecord to ("variable_" & counter as text) & ":" & "\"" & theItem & "\", "
end if
set theString to theString & theRecord
end repeat
end tell
set theRecordList to run script "{" & theString & "}"
… but I also guess that you won’t need one, cause handling a list is much easier …
You can do what you want. It takes an advanced technique to accomplish though… we use objective-c. An applescript record is a “dictionary” in objective-c. As such we use the “call method” technique to create the objective-c dictionary so we can create the variable names like you want. Then we put that dictionary in an applescript list so you can use it normally…
set myArray to {}
tell application "Automator Runner"
repeat with i from 1 to 9
set theKey to ("x" & i) as text
set thisDict to call method "dictionaryWithObject:forKey:" of class "NSDictionary" with parameters {i, theKey}
set myArray to myArray & thisDict
end repeat
end tell
return myArray