Post Reply 
Set System Variable in a program
02-27-2015, 05:56 AM
Post: #1
Set System Variable in a program
Apparently I am stuck again and need help....

When in RPN I can change Base Variable as follows:
2 'Base' ►
The only question I have HERE is why 2 is still resident on the stack. Is Base being evaluated after storing and can I turn that off?


However in a program I encountered serious difficulties with the above.
Part of my user keyboard is the following
Code:

base_active:=3;
base_key:=1;
SymbBaseMenu()
BEGIN
  LOCAL btn:=SoftMenu({{"hex","dec","bin","2int","2Real","#"},base_key});
  CASE
    IF btn=1 THEN base_key:=1 ; base_active:=4; RETURN " 32 4 R→B(3)"; END;
    IF btn=2 THEN base_key:=2 ; base_active:=3; RETURN " 32 3 R→B(3)"; END;
    IF btn=3 THEN base_key:=3 ; base_active:=1; RETURN " 32 1 R→B(3)"; END;
    IF btn=4 THEN 3 'Base' ► ;  END; //How to set Base to some value prior to RETURN statement above...
    IF btn=5 THEN RETURN "B→R()"; END;
    IF btn=6 THEN "#"; END;
   DEFAULT "";     
  END;

END;

What I tried to do is set Base to the corresponding value in CASE1..3 instead of the 'base_active' variable. I just can't get it to work... Is it too simple to see atm?
So can anybody help here? I remember someone (was it TW?) explained a non-cas program being executed in home Mode. So if you are able to store it in HOME, a program should be, too.


Tahnk you very much


suggestion: RETURN(30) at the end of a program seems to be still broken. I can't imagine why the people at HP don't see the beauty and the need of having something like above evaluated instantly, but returning ENTER would be, if working, a way to try.
Find all posts by this user
Quote this message in a reply
02-27-2015, 06:37 AM
Post: #2
RE: Set System Variable in a program
By doing
2 'Base' ►
you store the value 2 in the variable 'Base'. When you store a value in a variable it will remain on the stack, this is a normal behavior in RPN.

reto
Find all posts by this user
Quote this message in a reply
02-27-2015, 07:22 AM (This post was last modified: 02-27-2015 07:24 AM by Angus.)
Post: #3
RE: Set System Variable in a program
yes, but since there are no stack commands (afaik) like drop I was wondering if it could be avoided. At least when the programming issues are solved I expect that to be the next problem otherwise. ;-) In the case of my Program I could avoid that, but I want to get to a level where I am the master of my calculator.
Find all posts by this user
Quote this message in a reply
02-27-2015, 07:31 AM (This post was last modified: 02-27-2015 07:32 AM by Didier Lachieze.)
Post: #4
RE: Set System Variable in a program
In programming mode you cannot use RPN notation, so instead of:
Code:
IF btn=4 THEN 3 'Base' ► ;
you can try:
Code:
IF btn=4 THEN Base:=3;
Find all posts by this user
Quote this message in a reply
02-27-2015, 07:59 AM
Post: #5
RE: Set System Variable in a program
(02-27-2015 07:22 AM)Angus Wrote:  yes, but since there are no stack commands (afaik) like drop I was wondering if it could be avoided.
In RPN mode [Image: a0nqeh] acts as drop.
Find all posts by this user
Quote this message in a reply
02-27-2015, 08:42 AM
Post: #6
RE: Set System Variable in a program
I didn't know that ja can mix non-rpn assignments. Wenn invoking functions their rpn notation is needed. Like with r->b(). I will dig into that, thanks.

Well, backspace acts as drop, however the main questin is about programming. I was initially under the impression that I have to use rpn notation for assignments (calling functions do) which would result in 2 on the stack. Then I would have needed a drop() command. Not a key.
If assignments can ideed be done in the a:=b notation that would be no issue.
Find all posts by this user
Quote this message in a reply
02-27-2015, 11:14 AM (This post was last modified: 02-27-2015 11:41 AM by Angus.)
Post: #7
RE: Set System Variable in a program
Thanks a lot so far. Your information about Variable assignment was indeed helpful. I could change my Key to the following which pretty much satifies my needs. Only two points are left on my wishlist:

1) as mentioned numerous times before: getting rid of the needed keystroke <ENTER>. Having the returned String passed to the parser by a new command or RETURN(30) working. :-)
(Although you could see a positive aspect: If I just want to change the current Base setting I could e.g. hit F2 and abort. Base has changed and no conversion happens. As said if I try to see a positive side-effect)

2) Activate the Softkey permanently. When I need Integer Base conversions I would like to have my Softkey at hand. The F-Keys in Home are more or less useless anyway.

Further ideas and comments are always welcome! See screenshot about what I have in mind.

Code:

SymbBaseMenu()
BEGIN
  LOCAL base_key := Base+1;
  LOCAL btn:=SoftMenu({{"bin","oct","dec","hex","2int","2Real"},base_key});

  IF Entry=2 THEN //RPN
      CASE
        IF btn=1 THEN Base:=0;  RETURN " 32 1 R→B(3)"; END; //bin
        IF btn=2 THEN Base:=1;  RETURN " 32 2 R→B(3)"; END; //oct
        IF btn=3 THEN Base:=2;  RETURN " 32 3 R→B(3)"; END; //dec
        IF btn=4 THEN Base:=3;  RETURN " 32 4 R→B(3)"; END; //hex
//don't tie the integers to their base
        IF btn=5 THEN RETURN " R→B(1)"; END;
        IF btn=6 THEN RETURN " B→R()"; END;
       DEFAULT "";     
      END;
  ELSE
       RETURN "";
  END;
END;


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
Post Reply 




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