Post Reply 
Indirect addressing in HP PPL. Is it possible?
01-08-2014, 08:40 PM
Post: #2
RE: Indirect addressing in HP PPL. Is it possible?
(01-08-2014 08:18 PM)veeblefester Wrote:  How does one do 'indirect' addressing in HP PPL?

Example: variableoneâ–¶variablepointer;// These are both LOCAL variables. This line does not work.

LOCAL variableone contains data from user input.

LOCAL variablepointer contains the destination name of a User variable. The destination name has been constructed by some code, based on user input, and stored in variablepointer.

I need a line(s) to store the contents of variableone into a User variable pointed to by the content of variablepointer.

Note that it had been suggested that I try the EXPR command (page 391). This command, the parsing of a string, cannot bring about indirect addressing.

Thanks in advance for any help.

The following code takes the input n and saves it to myvar using the pointer varptr.

Code:

export myvar; // this is the variable that presumably is already existing

export test(n)
begin
  local var1=n, varptr="myvar";
  expr(varptr + ":=" + var1);
  input(varptr,"Variable name","Varname=","Enter the var name", "A");
  input(var1,"Variable value",varptr + "=","Enter the value to save",var1);
  expr(varptr + ":=" + var1)
end;

Usage: test(9), then when prompted, type G for the varname (no need for double quotes since varptr was initialized to be a string), then enter another number -- say 42.

Result: type mvar at the command line and you will see the value 9. Type G at the command line and the result is 42.

As you may have already figured out, this only works with variables that already exist. You will get an error if varptr contains a variable name that has not been created. As myvar was created by the program, and G is a global built-in variable, no problems arise.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Indirect addressing in HP PPL. Is it possible? - Han - 01-08-2014 08:40 PM



User(s) browsing this thread: 1 Guest(s)