User key assignment
06-11-2020, 06:01 AM
Post: #1
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
User key assignment
Hi all...!

Whenever I try to use an expression "KEY K_On()" (or any other key assignment) in Cristóbal De Jesús' program "A Simple Entry Mode Switcher" I receive an error when I check the code.

// Cycles over entry mode options.
KEY K_On()
BEGIN
LOCAL an:={"Textbook","Algebraic","RPN"};
Entry:=(Entry+1) MOD 3;

STARTVIEW(-1,1); // Refresh Home view BEFORE tagging...

TEXTOUT_P(an(Entry+1),G0,2,207,2,RGB(255,0,0));
FREEZE; // the mean part!
END;

The HP Prime I have is the latest one and has been updated to the latest ROM...

Any thoughts?

Thanks,

Rob
06-11-2020, 10:17 AM
Post: #2
 pinkman Member Posts: 240 Joined: Mar 2018
RE: User key assignment
Hi,
Your code seems ok, there is only the famous RETURN -1; that is missing (see https://www.hpmuseum.org/forum/thread-14929.html)

Code:
 KEY K_On()  BEGIN  LOCAL an:={"Textbook","Algebraic","RPN"};  Entry:=(Entry+1) MOD 3;  STARTVIEW(-1,1); // Refresh Home view BEFORE tagging... TEXTOUT_P(an(Entry+1),G0,2,207,2,RGB(255,0,0)); FREEZE; // the mean part! RETURN −1; END;
06-11-2020, 11:32 PM
Post: #3
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-11-2020 10:17 AM)pinkman Wrote:  Hi,
Your code seems ok, there is only the famous RETURN -1; that is missing (see https://www.hpmuseum.org/forum/thread-14929.html)

Code:
 KEY K_On()  BEGIN  LOCAL an:={"Textbook","Algebraic","RPN"};  Entry:=(Entry+1) MOD 3;  STARTVIEW(-1,1); // Refresh Home view BEFORE tagging... TEXTOUT_P(an(Entry+1),G0,2,207,2,RGB(255,0,0)); FREEZE; // the mean part! RETURN −1; END;

Hi pinkman...
I still get the error at the line "KEY K_On()"... (rather frustrating...!)
06-12-2020, 05:07 AM
Post: #4
 cyrille de brébisson Senior Member Posts: 999 Joined: Dec 2013
RE: User key assignment
Hello,

Is your program in PPL mode? or CAS?
Is the text that you showed us the ONLY text in the program?
I just tested here and it seems to work...

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.
06-12-2020, 10:12 AM
Post: #5
 Carlos295pz Senior Member Posts: 363 Joined: Sep 2015
RE: User key assignment
Maybe not the case.
It is possible that you have defined K_On 2 times in the same program, having it defined as the user key in other programs does not affect since the last compilation predominates.

Viga C | TD | FB
06-12-2020, 11:27 AM (This post was last modified: 06-12-2020 11:29 AM by rlinden12.)
Post: #6
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-12-2020 05:07 AM)cyrille de brébisson Wrote:  Hello,

Is your program in PPL mode? or CAS?
Is the text that you showed us the ONLY text in the program?
I just tested here and it seems to work...

Cyrille

Hi Cyrille...

Program/calculator is in PPL mode and the text as quoted is the entire code sequence...

I get the same error whether I use HP Connectivity kit (copy code to new program) or if I enter it into the PC desktop Prime as a new program.

I get the same problem when KEY K_Symb() is used...

Rob
06-12-2020, 12:13 PM
Post: #7
 Didier Lachieze Senior Member Posts: 1,181 Joined: Dec 2013
RE: User key assignment
Do you have selected the comma instead of the dot as the decimal separator?

If so, by adding the following line at the beginning of your program you'll make them compatible with any type of digit grouping setting.

Code:
#pragma mode( separator(.,;) integer(h32) )

Note: you can insert the pragma statement in the program editor with the [Menu] key followed by option 5. This is anyway a good programming practice when you share programs with people who can use different settings.
06-13-2020, 03:20 AM (This post was last modified: 06-13-2020 11:49 AM by rlinden12.)
Post: #8
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-12-2020 12:13 PM)Didier Lachieze Wrote:  Do you have selected the comma instead of the dot as the decimal separator?

If so, by adding the following line at the beginning of your program you'll make them compatible with any type of digit grouping setting.

Code:
#pragma mode( separator(.,;) integer(h32) )

Note: you can insert the pragma statement in the program editor with the [Menu] key followed by option 5. This is anyway a good programming practice when you share programs with people who can use different settings.

Thanks... However it's not applicable for me in this case Didier... I use the dot as my separator... Besides, the error is in the KEY statement with only the key code as a parameter...

The program runs and works perfectly IF I don't include the KEY_On() statement. It's the user key assignment function that seems to be broken...

Rob
06-18-2020, 01:38 AM
Post: #9
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-13-2020 03:20 AM)rlinden12 Wrote:
(06-12-2020 12:13 PM)Didier Lachieze Wrote:  Do you have selected the comma instead of the dot as the decimal separator?

If so, by adding the following line at the beginning of your program you'll make them compatible with any type of digit grouping setting.

Code:
#pragma mode( separator(.,;) integer(h32) )

Note: you can insert the pragma statement in the program editor with the [Menu] key followed by option 5. This is anyway a good programming practice when you share programs with people who can use different settings.

Thanks... However it's not applicable for me in this case Didier... I use the dot as my separator... Besides, the error is in the KEY statement with only the key code as a parameter...

The program runs and works perfectly IF I don't include the KEY_On() statement. It's the user key assignment function that seems to be broken...

Rob

Problem SOLVED!
When a new program is created on the Prime, it automatically starts with a statement EXPORT title(). I had left this statement in place and then had the KEY assignment function and the BEGIN/END statements.

For this code, the EXPORT statement has to be deleted...

A simple fix for a newbie!

Thanks for all the assists...!

Rob
06-18-2020, 05:27 AM
Post: #10
 pinkman Member Posts: 240 Joined: Mar 2018
RE: User key assignment
Congrats!

Cyrille gave you the clue, but maybe you did not take enough care to his question.
06-18-2020, 06:42 AM (This post was last modified: 06-18-2020 06:45 AM by Carlos295pz.)
Post: #11
 Carlos295pz Senior Member Posts: 363 Joined: Sep 2015
RE: User key assignment
For clear doubts:
EXPORT KEY K_On() BEGIN END; makes the function visible like any other function, K_On is a function like all the others that can be used inside or outside the program, but it will not behave as a user keyboard since that is only handled by KEY and the user keyboard.
The following code should also not fail:
Code:
EXPORT title1() BEGIN END; EXPORT KEY K_On BEGIN END;

Viga C | TD | FB
06-18-2020, 11:49 PM
Post: #12
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-18-2020 05:27 AM)pinkman Wrote:  Congrats!

Cyrille gave you the clue, but maybe you did not take enough care to his question.

Hi pinkman...

Now that the issue is resolved and that I've re-read Cyrille's advice, you are correct! But... as a complete newbie at this, I assumed that as HP automatically creates the EXPORT title(), BEGIN END; sequence, that that is a requirement for ALL programs... Now I know better...

THANKS!

Rob
06-18-2020, 11:51 PM
Post: #13
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-18-2020 06:42 AM)Carlos295pz Wrote:  For clear doubts:
EXPORT KEY K_On() BEGIN END; makes the function visible like any other function, K_On is a function like all the others that can be used inside or outside the program, but it will not behave as a user keyboard since that is only handled by KEY and the user keyboard.
The following code should also not fail:
Code:
EXPORT title1() BEGIN END; EXPORT KEY K_On BEGIN END;

Indeed Carlos... It does work! And of course now the program appears in the toolbox...

Rob
06-19-2020, 10:27 PM (This post was last modified: 06-19-2020 10:29 PM by pinkman.)
Post: #14
 pinkman Member Posts: 240 Joined: Mar 2018
RE: User key assignment
(06-18-2020 11:49 PM)rlinden12 Wrote:
(06-18-2020 05:27 AM)pinkman Wrote:  Congrats!

Cyrille gave you the clue, but maybe you did not take enough care to his question.

Hi pinkman...

Now that the issue is resolved and that I've re-read Cyrille's advice, you are correct! But... as a complete newbie at this, I assumed that as HP automatically creates the EXPORT title(), BEGIN END; sequence, that that is a requirement for ALL programs... Now I know better...

THANKS!

Rob

I wasn’t making fun of you, I was very sorry that you missed this clue. You would have won a few days.
Default EXPORT statement is useful if you just need to create a small function in its own program file. With time you’ll get used to append you utilities functions in one file, avoiding the collection of program files, because of the lack of real file management.
06-19-2020, 11:57 PM
Post: #15
 rlinden12 Junior Member Posts: 12 Joined: Feb 2014
RE: User key assignment
(06-19-2020 10:27 PM)pinkman Wrote:
(06-18-2020 11:49 PM)rlinden12 Wrote:  Hi pinkman...

Now that the issue is resolved and that I've re-read Cyrille's advice, you are correct! But... as a complete newbie at this, I assumed that as HP automatically creates the EXPORT title(), BEGIN END; sequence, that that is a requirement for ALL programs... Now I know better...

THANKS!

Rob

I wasn’t making fun of you, I was very sorry that you missed this clue. You would have won a few days.
Default EXPORT statement is useful if you just need to create a small function in its own program file. With time you’ll get used to append you utilities functions in one file, avoiding the collection of program files, because of the lack of real file management.

pinkman..., I definitely didn't take your message as poking fun at me! No need to apologise! I'm just grateful for the advice!
 « Next Oldest | Next Newest »

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