HP Forums
Prime Programming help needed for a (still) newb Prime user - 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: Prime Programming help needed for a (still) newb Prime user (/thread-17120.html)



Prime Programming help needed for a (still) newb Prime user - spiff72 - 06-17-2021 07:00 PM

Hello all,

I have a programming question that is trivial on my HP50g, but not so much with the Prime.

I often use my calculator as a simple "counter" for incrementing a number on the stack by a varying number, and I assign simple programs for these to softkeys.

The simplest possible example (as I do it on the 50g) - "count by 1":
<< 1 + >>

I store this as "CNT1", and press the softkey for it (after initially putting a zero on the stack), and I can increment the value on the stack with one button press.

For the Prime, I came up with a simple prog:
Code:
// change the value in the RETURN statement for
// different count increments
EXPORT countby(c1)
BEGIN
 RETURN c1+1;
END;

KEY K_Comma()
BEGIN
 RETURN "countby()";
END;

The above works, and assigns the countby() program to the unshifted comma key for the user keyboard.

In practice this is rather clunky, though:
- Put zero on stack
- Press shift
- Press Help (for user keyboard)
- Press comma key (which puts countby() in the command line)
- Press enter

Is there a more elegant way to do this without requiring 4 keypresses? (Maybe within a custom app with an option to change the count increment?)

Just fishing for ideas - I am sooo used to the RPL programming that this Prime is hard to get used to!


RE: Prime Programming help needed for a (still) newb Prime user - Liamtoh Resu - 06-17-2021 07:52 PM

The user guide has a brief explanation on the GETKEY function.
Apparently the code for the comma is 29.

I have not coded an example yet.

Thanks.


RE: Prime Programming help needed for a (still) newb Prime user - C.Ret - 06-17-2021 08:52 PM

Hello,

To use my HP prime as a simple counter, I never made something so elaborate.

In HOME or CAS view, I press [ 0 ] [ ENTER ] to enter zero in the results stack.
Then I press [ Shift ][ Ans ] [ + ] [ 1 ] [ENTER] to initiate increment by one.
Then any further press on [ ENTER ] increase the “counter” one more unit.

If you whish, you can program the "Ans+1"; sequence on a specific User key to spare a few keystrokes.


RE: Prime Programming help needed for a (still) newb Prime user - spiff72 - 06-17-2021 11:39 PM

(06-17-2021 08:52 PM)C.Ret Wrote:  Hello,

To use my HP prime as a simple counter, I never made something so elaborate.

In HOME or CAS view, I press [ 0 ] [ ENTER ] to enter zero in the results stack.
Then I press [ Shift ][ Ans ] [ + ] [ 1 ] [ENTER] to initiate increment by one.
Then any further press on [ ENTER ] increase the “counter” one more unit.

If you whish, you can program the "Ans+1"; sequence on a specific User key to spare a few keystrokes.

EDIT:
Just tried it out - that works for me! It doesn't work in the "home" screen when in RPN mode (my usual mode), but in CAS mode it works nicely.

Thanks again!

Hmmm - I will try that out. Thanks!


RE: Prime Programming help needed for a (still) newb Prime user - C.Ret - 06-18-2021 04:50 PM

That's a fact, I never use my HP Prime in RPN mode, I have much better hardware for this.