Post Reply 
User-Key
11-16-2015, 01:50 PM
Post: #1
User-Key
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.
Find all posts by this user
Quote this message in a reply
11-16-2015, 02:51 PM
Post: #2
RE: User-Key
Use Shift+Help to enable the user keyboards. Twice to held it active (for K_Mul)

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
11-16-2015, 03:12 PM
Post: #3
RE: User-Key
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.
Find all posts by this user
Quote this message in a reply
11-16-2015, 03:14 PM (This post was last modified: 11-16-2015 03:15 PM by Han.)
Post: #4
RE: User-Key
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
11-16-2015, 03:18 PM
Post: #5
RE: User-Key
(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

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
11-16-2015, 04:10 PM
Post: #6
RE: User-Key
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.
Find all posts by this user
Quote this message in a reply
11-17-2015, 06:29 AM
Post: #7
RE: User-Key
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

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
11-17-2015, 10:02 AM
Post: #8
RE: User-Key
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.
Find all posts by this user
Quote this message in a reply
Post Reply 




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