HP Forums
User Variables - 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: User Variables (/thread-825.html)



User Variables - veeblefester - 03-05-2014 08:44 PM

Is there a line of code that will create a USER VARIABLE from within a program?

I have tried many variations.

Thanks in advance for any help.


RE: User Variables - Han - 03-06-2014 03:14 AM

(03-05-2014 08:44 PM)veeblefester Wrote:  Is there a line of code that will create a USER VARIABLE from within a program?

I have tried many variations.

Thanks in advance for any help.

If you don't care that it is a CAS variable, then yes.
Code:

EXPORT MAKEVAR(string)
BEGIN
  string:=string+":=0;";
  CAS(string);
END;

Usage: MAKEVAR("var1") -- creates a CAS variable named var1 with an initial value of 0. Some caveats: even though a CAS variable is global, the program will not know about it until it gets created (i.e. it presumably does not exist during compilation). So you will need to be careful with your code -- but indirection would be fine.

And now for a small digression...

A CAS variable is much more versatile. You can even use it in the solver app. This means you can create your own equation library program that dynamically creates variables without actually having to predefine them, despite what many previous posts seem to suggest. And when you're done, you can purge them with the purge() command.


RE: User Variables - cyrille de brébisson - 03-06-2014 06:20 AM

Hello,


Quote:Is there a line of code that will create a USER VARIABLE from within a program?

assuming that you are not talking CAS here...

If you are trying to create a user variable akind to the ones created when you type something like abc:=5 on the command line, then the answer is no.

If you are trying to create a user variable using a name provided by the user, no...

You can create global variables in your program using EXPORT though.

Cyrille


RE: User Variables - veeblefester - 03-06-2014 12:01 PM

Thanks Han. That will be useful in the future. It will not however, help me in this situation.

Thanks Cyrille.

What a fundamental flaw in the operating system.