HP Forums
User-Key - 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: User-Key (/thread-5143.html)



User-Key - Dirk. - 11-16-2015 01:50 PM

Hello,
maybe I dont't understand the concept at all - maybe you can explain to me what happens:

I put the following code into a program:

KEY K_Mul()
BEGIN
RETURN 42;
END;

After pressing pressing Shift Help * in home-environment I get
1 as answer - but I expected 42

I also have a function
EXPORT ENG()
BEGIN
RETURN 42;
END;

which answers 42 as I expected.

Hm, this really puzzles me... I'm not understanding what I'm doing...

Thank you
Dirk.


RE: User-Key - eried - 11-16-2015 02:51 PM

Use Shift+Help to enable the user keyboards. Twice to held it active (for K_Mul)


RE: User-Key - Didier Lachieze - 11-16-2015 03:12 PM

Try with:

KEY K_Mul()
BEGIN
RETURN "42";
END;

See page 561 of the English manual. A user Key program is expected to return a string.


RE: User-Key - Han - 11-16-2015 03:14 PM

If you return only a numerical (integer) value, then the system will apply the key corresponding to that value. The 1 returned is from carrying out button 42, which is the 1 key.


RE: User-Key - eried - 11-16-2015 03:18 PM

(11-16-2015 03:14 PM)Han Wrote:  If you return only a numerical (integer) value, then the system will apply the key corresponding to that value. The 1 returned is from carrying out button 42, which is the 1 key.

Oh! good to know


RE: User-Key - Dirk. - 11-16-2015 04:10 PM

Thank you very much,
well, this is an interesting feature which did not become clear for me when reading the german translation of the user guide.
So the behaviour of RETURN-statement is different when called in a "normal" function from the behaviour when called in a "KEY"-Function.
Why would I want to "apply a key" as a result instead of returning a value?

Would it be possible, to return "42" (i.e. put it into the entry-line") and "apply" the Enter-Key afterwards to have it as a "normal" result avaliable on screen and in the Ans-variable. This would save the user from pressing Enter.

Thank you very much.
Dirk.


RE: User-Key - cyrille de brébisson - 11-17-2015 06:29 AM

Hello,

Nope, sorry, you can only perform one operation at this time...
At one point, I tried to make it more versatile but did not succeed..

Cyrille


RE: User-Key - Dirk. - 11-17-2015 10:02 AM

Thank you very much for your answer.
I find it a bit irritating, that the return statement not always behaves the same.
however, maybe, it is possible to introduce a possibility to push something onto the "home stack" or have an "exit" statement behaving like I would the "return" expect to behave... or "fix" the "return" and have an additional "exit".

This could help to develop very convenient sequences of "user-key macros".

A further idea might be the addition of some sort of cursor-position-parameter, which would allow to position the cursor back, for example into the brackets just printed by the function.

Greetings
Dirk.