HP Forums
Single User Defined Program Key Press to Answer. - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Single User Defined Program Key Press to Answer. (/thread-17218.html)



Single User Defined Program Key Press to Answer. - matalog - 07-06-2021 09:39 PM

This little program, will take the last entry in the stack (in Algebraic mode anyway) and use it to display the subtotal, and amount of tax.

Code:
KEY K_Ln()
BEGIN
LOCAL G:=ROUND(Ans(1)/1.2,2);
LOCAL H:=ROUND(Ans(1)/6,2);
LOCAL I:={};
I(1):=G;
I(2):=H;
MSGBOX(I);
RETURN 46;
END;

It assumes the last number on the stack is the total including tax, and that you want, what the total would have been before tax, and the amount of tax. Pressing LN activates it.

Rather than teaching people how to calculate tax, it is an example of a program that works by a single keypress and displays a result.

Return 46; at the end of the program ensures that the program doesn't return anything to the stack, or the live calculator line. It basically presses the On button, which I assume to be harmless.

Any suggestions of a way to get the result to the stack would be very welcome!


RE: Single User Defined Program Key Press to Answer. - kevinwaite - 07-09-2021 07:27 PM

Hello, how did you learn RETURN 46; is like pressing the on button?
Might you know the value for the ENTER key?


RE: Single User Defined Program Key Press to Answer. - matalog - 07-09-2021 09:52 PM

(07-09-2021 07:27 PM)kevinwaite Wrote:  Hello, how did you learn RETURN 46; is like pressing the on button?
Might you know the value for the ENTER key?

I have attached the image from page 652 of the manual, which describes what the rules are for GETKEY. I discovered that the result of a program (or key instruction) written this way, will be that the 'number' returned, will show itself as the key that the 'number' represents.

The ENTER key will be 30 and shift and ENTER should be 51+30, with alpha+ENTER being 51+51+30, and shift+alpha+ENTER being 51+51+51+30.

I assume that there could be some use for this, but I cannot think of a good one off hand. The use of a Key instruction program like this, seems to be bound to only outputting a single instruction to be used to simulate the press of a key.


RE: Single User Defined Program Key Press to Answer. - Albert Chan - 07-09-2021 10:43 PM

(07-06-2021 09:39 PM)matalog Wrote:  Return 46; at the end of the program ensures that the program doesn't return anything to the stack, or the live calculator line. It basically presses the On button, which I assume to be harmless.

Not quite harmless. On button clear line entry.

Return ""; may be more "harmless".


RE: Single User Defined Program Key Press to Answer. - kevinwaite - 07-11-2021 04:29 AM

RETURN 46;

On my hp prime puts 46 on the level 1: stack location.

Hmm?


RE: Single User Defined Program Key Press to Answer. - matalog - 07-11-2021 09:45 AM

(07-11-2021 04:29 AM)kevinwaite Wrote:  RETURN 46;

On my hp prime puts 46 on the level 1: stack location.

Hmm?

It sounds like you didn't use the program at the start of this post. The behaviour you describe is what people here actually want, but it isn't attainable from a single key press. What you are describing is usually achieved by adding RETURN 46; just before END; in a normal program that begins with EXPORT NAME(), and not KEY N_AME().