First, some AppleScript terminology:
{A5:“100”, A6:“100”, A3:“B”, L1:“U”, D1:“V”} is a record.
A5:“100” is a field in that record.
A5 is the field’s label.
“100” is the field’s value.
Since a label is in effect a keyword - indicating an element of a record - it can’t be held in a variable, either as a label or in string form. It’s therefore best not to write scripts in a way that depends on this being possible.
However, if it’s unavoidable, there is a cheat you can use:
property cl : {A5:"100", A6:"100", A3:"B", L1:"U", D1:"V"}
on getValueUsingLabelString(theRecord, labelString)
try
-- Some nonsense that generates an error message
theRecord as integer
on error errMsg
-- errMsg is "Can't make {A5:"100", A6:"100", A3:"B", L1:"U", D1:"V"} into a integer."
set ASline to labelString & " of " & text 12 thru -17 of errMsg
-- ASline is "A5 of {A5:"100", A6:"100", A3:"B", L1:"U"}"
return (run script ASline)
end try
end getValueUsingLabelString
set myVar to "A5"
getValueUsingLabelString(cl, myVar)
--> "100"
But this is only good for reading fields. If you want to set them, you’ll need another cheat - which has a rather inportant proviso. Record labels are stored internally as lower-case strings. Normally this doesn’t make any difference, but the cheat below expects the supplied label string to be lower case, otherwise it creates a barred version of the label - eg. |A5| instead of just A5. These are not treated as the same label. So either the label strings must always be lower case, or they must be converted during the cheat. Here, I’ve used ‘lowercase’ from the Satimage OSAX:
property cl : {A5:"100", A6:"100", A3:"B", L1:"U", D1:"V"}
on setValueUsingLabelString(theRecord, labelString, thevalue)
script o
-- 'lowercase' requires the Satimage OSAX
{«class usrf»:{lowercase labelString, thevalue}}
end script
-- Create a one-field record with the required label and value
-- and concatenate the original record to it
return (run script the result) & theRecord
end setValueUsingLabelString
set myVar to "A5"
set cl to setValueUsingLabelString(cl, myVar, "Hello!")
--> {A5:"Hello!", A6:"100", A3:"B", L1:"U", D1:"V"}