HP Forums
Learning to program on the HP Prime (intermediate to advanced) - 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: Learning to program on the HP Prime (intermediate to advanced) (/thread-15698.html)



Learning to program on the HP Prime (intermediate to advanced) - Grayhek - 10-09-2020 03:42 AM

I have learned to program quite a bit while taking my ChemE courses but it has been quite difficult finding good help on things that aren't clear or are not even in the user manual for the HP Prime (this forum is very helpful). What I would like to know is if there are any materials or courses that teach you how to program better for the HP Prime or is it just trial and error? I see some people make amazing programs and apps for the Prime but I have no idea how they learned to do all of that stuff. If someone could point me to some learning materials that would be much appreciated.


RE: Learning to program on the HP Prime (intermediate to advanced) - rawi - 10-09-2020 09:38 AM

Perhaps the following link might be helpful:
http://www.hp-prime.de/files/composite_file/file/201-programming-in-hp-ppl.pdf

Best
Raimund


RE: Learning to program on the HP Prime (intermediate to advanced) - Grayhek - 10-09-2020 11:23 AM

(10-09-2020 09:38 AM)rawi Wrote:  Perhaps the following link might be helpful:
http://www.hp-prime.de/files/composite_file/file/201-programming-in-hp-ppl.pdf

Best
Raimund

I have looked at that before and it does have some useful information. I am looking for something with more information. That pdf has showed me a few things but I still had to look at someone elses code to figure out how to format the input screen or use the CHOOSE function. If I could find something that will teach how to format the screen/code and also how to use calculator functions better or in new ways, that would be amazing.


RE: Learning to program on the HP Prime (intermediate to advanced) - pinkman - 10-09-2020 09:50 PM

I don’t know if this will be of great help: I found this good tutorial, but it is in French.
http://mic.nic.free.fr/hp/Livret%20HP%20Prime.pdf

Maybe, if you don’t speak French, with screen captures and the use of Google translate you could find some help.

I think you should also feel free to post your tries here, and let the people suggest their improvements or their tricks.
You can even post lots of questions at a time, there are people here who are not afraid of long posts.


RE: Learning to program on the HP Prime (intermediate to advanced) - pinkman - 10-09-2020 10:16 PM

... And of course the built in Help is very important for your learning curve.

Here is a simple “INPUT” example with radio button behavior:

Code:


EXPORT CHECKTEST()
BEGIN
 LOCAL I, R, I1, I2, I3, I4, I5;
 R := INPUT({{I1,4,{25,10,1}}, {I2,0,{25,10,2}}, {I3,0,{25,10,3}}, {I4,0,{25,10,4}}, {I5,0,{25,10,5}}},
      "Make your choice",
      {"Choice 1","Choice 2","Choice 3","Choice 4", "Choice 5"},
      {"Help text #1", "Help text #2", "Help text #3", "Help text #4", "Help text #5"});
 IF R THEN
  I := I1 + I2 * 2 + I3 * 3 + I4 * 4 + I5 *5;
  IF I THEN
   MSGBOX("You chose " + STRING(I));
  ELSE
   MSGBOX("You chose nothing");
  END; 
 ELSE
  MSGBOX("You canceled your choice");
 END;
END;

Edit: corrected after bug detection on I assignation


RE: Learning to program on the HP Prime (intermediate to advanced) - tcab - 10-10-2020 12:04 AM

With that sample program, I always get the message that I chose nothing. I think the value of I is being checked before it gets assigned.


RE: Learning to program on the HP Prime (intermediate to advanced) - pinkman - 10-10-2020 02:41 AM

(10-10-2020 12:04 AM)tcab Wrote:  With that sample program, I always get the message that I chose nothing. I think the value of I is being checked before it gets assigned.

Shame on me!
Var “I” was assigned two lines too late. Corrected in the original post.


RE: Learning to program on the HP Prime (intermediate to advanced) - tcab - 10-10-2020 04:03 AM

Thanks, works fine now.

Playing around a bit, it looks like MSGBOX works OK if you pass it the integer I without converting it to a string. Also, returning I might be a nice enhancement if the user wants the value on the main calculator history/stack. E.g.

PHP Code:
MSGBOX("You chose " I);
return 
I

I know it's a toy program, but this information might help the original poster.


RE: Learning to program on the HP Prime (intermediate to advanced) - pinkman - 10-12-2020 10:34 PM

Yes good idea of course.

To the OP: if your function doesn’t explicitly returns a value, then it returns the last calculated value of the function.

You also asked to learn how to use CHOOSE, well there is less mystery.

Code:

EXPORT CHOOSETEST()
BEGIN
 LOCAL CHOICE, LST := {"Apple","Pear","Cherry","Orange"};
 CHOOSE(CHOICE,"Make your choice", LST);
 IF CHOICE THEN
  MSGBOX("You chose " + LST[CHOICE]);
 ELSE
  MSGBOX("You chose nothing");
 END; 
 RETURN CHOICE; 
END;