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
 matalog Member Posts: 104 Joined: May 2021
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;
09-26-2021, 09:25 PM
Post: #2
 cext104 Junior Member Posts: 1 Joined: May 2021
RE: Help with a program
Maybe you should END your program
09-27-2021, 03:53 PM (This post was last modified: 09-27-2021 03:53 PM by pinkman.)
Post: #3
 pinkman Senior Member Posts: 393 Joined: Mar 2018
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
09-27-2021, 05:24 PM
Post: #4
 Albert Chan Senior Member Posts: 1,676 Joined: Jul 2018
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
 « Next Oldest | Next Newest »

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