Post Reply 
Help with a program
06-24-2021, 10:56 PM (This post was last modified: 06-24-2021 10:58 PM by matalog.)
Post: #1
Help with a program
I have been trying to make a program to leave the leading zeroes on a number, just to get a quick look at them, and experiment with the calculator.

I have got this far, and it seems that at the first reference to Ans() is being taken from Home mode, not CAS, and the second use of Ans() is being taken from CAS. So, if the number in history in home screen, and CAS are of the same order, then it actually works fine.

Can anyone offer any guidance as to how I can get it to correctly use the number in the CAS history, to set the length

Code:
EXPORT CDEC()
BEGIN
LOCAL f:=STRING(Ans(1));
LOCAL g:="";
LOCAL h:="";
LOCAL i:=0;
g:=RIGHT(f,2);
i:=EXPR(g);
i:=i+2;
h:="f"+STRING(i);
MSGBOX(format(Ans(1),h));
END;
Find all posts by this user
Quote this message in a reply
09-26-2021, 09:25 PM
Post: #2
RE: Help with a program
Maybe you should END your program
Find all posts by this user
Quote this message in a reply
09-27-2021, 03:53 PM (This post was last modified: 09-27-2021 03:53 PM by pinkman.)
Post: #3
RE: Help with a program
Your program is a Home program, not a CAS program.
I guess that when it calls Ans (1st time) it gets the Home Ans, but the second time it calls Ans from the format() function, which is a CAS function, thus leading to get Ans from CAS.

If this is true it means you'll have erratic behaviors because of confusing Home and CAS.
You should declare your program as a CAS program and run it from the CAS View.

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
09-27-2021, 05:24 PM
Post: #4
RE: Help with a program
Hi, pinkman

Your guess confirmed. With CAS Ans = 0

HOME> 1
HOME> id(Ans)       → 0

But, we should seriously considered this behavior a bug.
Ans is really a shorthand for "previous answer".
It should be related to where the environment was called from.

For above example, HOME> id(Ans) should return 1
Find all posts by this user
Quote this message in a reply
Post Reply 




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