Indirect addressing in HP PPL. Is it possible?
|
01-08-2014, 08:18 PM
Post: #1
|
|||
|
|||
Indirect addressing in HP PPL. Is it possible?
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. Happy coding and may you see ' i No errors in the program ' with every compilation. |
|||
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? The following code takes the input n and saves it to myvar using the pointer varptr. Code:
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 |
|||
01-09-2014, 09:05 PM
(This post was last modified: 01-09-2014 10:55 PM by veeblefester.)
Post: #3
|
|||
|
|||
RE: Indirect addressing in HP PPL. Is it possible?
The code below does not work when var1 is a string.
The reason I claimed that EXPR could not bring about indirect addressing is because I experimented with EXPR using a string. In the app I am developing, var1 is a string. This is very curious, when var1 is a string, in edit the check reports no errors. However, at runtime a syntax error is caused by the EXPR line. I tested your EXPR line, it works perfectly if var1 is a real, integer or symbolic. Any thoughts on making the EXPR line work when var1 is a string? Thanks in advance for any help. EXPORT SYMBOL1; EXPORT test2() BEGIN LOCAL var1="a string",varptr="SYMBOL1"; INPUT(varptr,"Variable Name","Varnam=","Enter the var name","A");// Key in SYMBOL1 EXPR(varptr + ":=" + var1); END; Happy coding and may you see ' i No errors in the program ' with every compilation. |
|||
01-09-2014, 09:32 PM
(This post was last modified: 01-10-2014 12:26 AM by Han.)
Post: #4
|
|||
|
|||
RE: Indirect addressing in HP PPL. Is it possible?
Edit: The + operator is overloaded to handle strings. That is, when one of the arguments is a string then it will convert the other argument to a string if it is a non-string. If the object is already a string, no conversion happens.
Use the TYPE command to check whether or not your variable is a string. Make sure that the TYPE command is in all uppercase as there is a different command of the same name but in all lowercase. Then use the STRING command on the variable. I recommend typing string in all uppercase as well. Example: Code:
Graph 3D | QPI | SolveSys |
|||
01-10-2014, 07:02 AM
Post: #5
|
|||
|
|||
RE: Indirect addressing in HP PPL. Is it possible?
The following code
EXPORT SYMBOL1,WHATTYPE; EXPORT test2() BEGIN LOCAL var1="why",varptr="SYMBOL1"; INPUT(varptr,"Variable Name","Varnam=","Enter the var name","A");// Key in SYMBOL1 TYPE(var1)▶WHATTYPE; EXPR(varptr + ":=" + var1);// When var1 is a string, this line causes a syntax error when the program is Run but not during Check in Edit! END; produces these results TYPE(var1)▶WHATTYPE stores the following: var1 = 3.14 stores 0 and the program runs fine. var1 = π (pi) stores 0 and the program runs fine. var1 = "why" stores 2 and the program halts with a syntax error from line EXPR(varptr + ":=" + var1); even though the Check function in Edit reports no errors! Happy coding and may you see ' i No errors in the program ' with every compilation. |
|||
01-10-2014, 03:36 PM
Post: #6
|
|||
|
|||
RE: Indirect addressing in HP PPL. Is it possible?
(01-10-2014 07:02 AM)veeblefester Wrote: The following code You never added the line: if TYPE(var1)==2 then var1:=STRING(var1); end; just above the expr() command. Graph 3D | QPI | SolveSys |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)