Page 1 of 1
Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 4:49 pm
by sritcp
I have a repeat loop that strings together the names of custom properties
Code: Select all
repeat for each item tMenuChoice in sMenuList
put the ("c" & tMenuChoice & "NumOfParas") of this card into tNum
........
which gives the compilation error: "Expression: bad factor" in the parenthesized region.
The parenthesis parses correctly if tested independently.
This raises a question: Do property names always have to be literal? That is, is the statement
put the variableContainingPropertyName of the yourObject
not possible?
Thanks,
Sri.
Re: Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 4:53 pm
by Klaus
Hi sri,
use IT:
Code: Select all
repeat for each item tMenuChoice in sMenuList
get "c" & tMenuChoice & "NumOfParas"
put the IT of this card into tNum
........
or a variable with its name already concatenated!
Code: Select all
repeat for each item tMenuChoice in sMenuList
put "c" & tMenuChoice & "NumOfParas" into tProp
put the tProp of this card into tNum
........
Best
Klaus
Re: Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 4:56 pm
by magice
Try it in a "do" statement.
Re: Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 5:07 pm
by FourthWorld
The suggestions given thus far are good ones, and here's one more I find especially convenient for cases in which I need to work with property names that can't be known in advance: use array syntax.
This will put a value into a custom property within a custom property set named "MyPrefs", and the second handler retrieves it:
Code: Select all
on SetValue pKey, pVal
set the MyPrefs[pKey] of stack "SomePrefs" to pVal
save stack "SomePrefs"
end SetValue
on GetValue pKey
return the MyPrefs[pKey] of stack "SomePrefs"
end GetValue
Re: Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 5:42 pm
by sritcp
Thanks everyone, for the suggestions!
Klaus,
I didn't think of trying
Code: Select all
put "c" & tMenuChoice & "NumOfParas" into tProp
put the tProp of this card into tNum
because I thought that was
exactly what parenthesis did (evaluate what is inside it and put it in a temporary variable).
I guess logic doesn't always work!
Regards,
Sri.
Re: Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 6:02 pm
by Klaus
Hi sri,
sritcp wrote:Klaus,
I didn't think of trying
Code: Select all
put "c" & tMenuChoice & "NumOfParas" into tProp
put the tProp of this card into tNum
because I thought that was
exactly what parenthesis did (evaluate what is inside it and put it in a temporary variable).
I guess logic doesn't always work!
yep, the parenthesis sound logical, but the engine is extremely picky in this case
Best
Klaus
Re: Using a variable to refer to custom properties
Posted: Thu Mar 05, 2015 8:44 pm
by phaworth
I entered bug# 13086 at the QCC q wgile back. Seemed to get a favorable review by Mark Waddingham but it hasn't been fixed yet.
Pete