HP Forums
How to store value into variable which is as value of another variable? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: How to store value into variable which is as value of another variable? (/thread-5309.html)



How to store value into variable which is as value of another variable? - chromos - 12-11-2015 08:15 AM

I am not sure if I can explain it understandably...

I cannot store value into variable directly because I don't know its name. But I know that its name is stored in other known variable.

For example:
I have something like this: L1(1):="VarNameChoosenByUserViaInput";
I can view value stored in VarNameChoosenByUserViaInput with EXPR(L1(1)), but how I can change value in that variable via L1(1) indirectly?

Thanks for any advice.


RE: How to store value into variable which is as value of another variable? - Didier Lachieze - 12-11-2015 08:27 AM

(12-11-2015 08:15 AM)chromos Wrote:  I have something like this: L1(1):="VarNameChoosenByUserViaInput";
I can view value stored in VarNameChoosenByUserViaInput with EXPR(L1(1)), but how I can change value in that variable via L1(1) indirectly?

This should work :
EXPR(L1(1)+":="+STRING(value))
or :
EVAL(L1(1):=value)


RE: How to store value into variable which is as value of another variable? - chromos - 12-11-2015 09:21 AM

Thank you very much, Didier, first example works.
Second example doesn't - it changes variable L1(1) and not variable inside L1(1).


RE: How to store value into variable which is as value of another variable? - Didier Lachieze - 12-11-2015 01:07 PM

(12-11-2015 09:21 AM)chromos Wrote:  Second example doesn't - it changes variable L1(1) and not variable inside L1(1).
Yes, you're right..

Regarding the first example, a few comments:
  • if value is a numeric value, then it's better to use STRING(value,1) rather than STRING(value): EXPR(L1(1)+":="+STRING(value,1))
    This way you ensure by using the standard format that the string created with include all digits of "value", otherwise if for ex. you are in engineering 2 display mode, only the first 3 digits will appear in the string.
  • if value is a variable, for example variable A, then to avoid the string translation just use: EXPR(L1(1)+":=A")



RE: How to store value into variable which is as value of another variable? - chromos - 12-11-2015 10:53 PM

Thank you, Didier.


RE: How to store value into variable which is as value of another variable? - Vtile - 12-12-2015 03:47 AM

I think what you are asking is known as indirect addressing.