Post Reply 
Calling a Program from Home Page. What's Wrong
12-10-2014, 07:32 AM
Post: #1
Calling a Program from Home Page. What's Wrong
New user.
Wrote my first program. Catesian Coord System

P2RN - Polar 2 Rectangular North Coordinate
A = Azimuth
D = Distance

Return a difference in Northing


==================
EXPORT P2RN(A,D)
BEGIN
//

LOCAL N;
N:=COS(A)*D;

RETURN N;

END;
==================


Run this "P2RN(45,100)"

from the Home Screen and get:

"Error: Syntax Error"

Have tried using variables for input after storing values into them.

Can't call "P2RN(45,100)" from another program either.

Works with "Run" in program Editor however.

what am I doing wrong?
Find all posts by this user
Quote this message in a reply
12-10-2014, 09:25 AM (This post was last modified: 12-10-2014 11:12 AM by Gilles.)
Post: #2
RE: Calling a Program from Home Page. What's Wrong
Hi !

I dont have my HPPrime here and perhaps this is not the problem. But I think these are good practices :

1/ Avoid ' LOCAL N; ' declaration : A..Z variables are global and predefined by default as reals.

If you want local variables prefer lower case: LOCAL n;

2/ In my opinion, avoid to use global variables as parameters. The code becomes :

Code:

EXPORT P2RN(a,d)
BEGIN
//

LOCAL n;
n:=COS(a)*d;

RETURN n;

END;

Note that

Code:

EXPORT P2RN(a,d)
BEGIN
 RETURN COS(a)*d;
END;

or even
Code:

EXPORT P2RN(a,d) 
BEGIN 
 COS(a)*d; 
END;

are simpler and does the job
Find all posts by this user
Quote this message in a reply
12-10-2014, 03:45 PM (This post was last modified: 12-10-2014 03:46 PM by Tim Wessman.)
Post: #3
RE: Calling a Program from Home Page. What's Wrong
(12-10-2014 07:32 AM)bobkrohn Wrote:  Run this "P2RN(45,100)"

You running in RPN mode?

Try 45 100 P2RN ENTER - possibly 45 100 P2RN(2)

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
12-10-2014, 04:29 PM (This post was last modified: 12-10-2014 04:32 PM by CR Haeger.)
Post: #4
RE: Calling a Program from Home Page. What's Wrong
Congrats on starting to program the Prime! If you are after short programs/scripts, consider creating it in CAS.

P2RN(a,d):=approx(d*cos(a))

Which will show up in Vars/CAS/Program. Now, in:

CAS: P2RN(45,100) gives 70.71
Home: P2RN(45,100) gives "
Home (RPN): 45 100 P2RN(2) gives "

I used approx() as I assume you dont want symbolic exact answers. Have fun.
Find all posts by this user
Quote this message in a reply
12-11-2014, 05:12 AM (This post was last modified: 12-11-2014 11:30 AM by bobkrohn.)
Post: #5
RE: Calling a Program from Home Page. What's Wrong
I tried changing all the variables.
ex. "A" changed to "Azimuth"
Still getting the same error message when run in Home.
Works fine when "Run" in Program Editor.
Syntax Check doesn't find any problem.
Just tried it in CAS and it works.

I'm in Algebraic Mode if that makes a diff.
And still a problem when called from another program.
There shouldn't be but maybe there is some setting somewhere that's causing the problem?
Find all posts by this user
Quote this message in a reply
12-11-2014, 11:21 AM (This post was last modified: 12-11-2014 11:26 AM by bobkrohn.)
Post: #6
RE: Calling a Program from Home Page. What's Wrong
In Emulator (will also try on calculator later)
In non-CAS

EXPORT P2RN(a,d)__________[DOES NOT WORK]
BEGIN
RETURN COS(a)*d;
END;


EXPORT test1(a,d)__________[works OK]
BEGIN
RETURN COS(a)*d;
END;

EXPORT test1(A,D)__________[works OK]
BEGIN
RETURN COS(A)*D;
END;

EXPORT test1(A,D)__________[works OK]
BEGIN
LOCAL N;
N:=COS(A)*D;
RETURN N;
END;

I just can't believe the HP-Prime operating system is this horribly buggy.
Inexcusable. What other crazy problems are there yet to be discovered?
Especially since it's been on the market this long.
Of course I've always had this quirk of, right off the bat, being able to discover bugs in software.

And it's not just using the variable "P2RN" for a program. Several other names cause a problem.
Having a number in second position?
Maybe it's interpreting it as P*2*RN ? Who knows.
____(try typing "P2RN" into the HOME screen)
Using "PRN" works.
Wait, "PR2N" doesn't work either.
Ahhh. "PRN2" works.
So maybe if there is a number in the name it has to be in the last position??
Hey, "P_RN" works.
Crazy.
Find all posts by this user
Quote this message in a reply
12-11-2014, 11:52 AM
Post: #7
RE: Calling a Program from Home Page. What's Wrong
That's strange:
I've tested
Code:
EXPORT P2RN(a,d) BEGIN COS(a)*d END;
on both (device + emulator: 6940) and it worked as expected.
Is there any other program on your calc which has defined an exported variable or function named "P2RN"? You may try the full name: <PROGNAME>.P2RN(...).


Attached File(s) Thumbnail(s)
   
Find all posts by this user
Quote this message in a reply
12-11-2014, 12:12 PM
Post: #8
RE: Calling a Program from Home Page. What's Wrong
Code:
EXPORT P2RN(a,d)
BEGIN 
RETURN COS(a)*d;
END;

Works fine here. Did you try 'restart' to clear vars? Also, (after an emulator back up): Calculator | Reset, may be helpful.
Find all posts by this user
Quote this message in a reply
12-11-2014, 12:41 PM
Post: #9
RE: Calling a Program from Home Page. What's Wrong
(12-10-2014 07:32 AM)bobkrohn Wrote:  New user.
Wrote my first program. Catesian Coord System

P2RN - Polar 2 Rectangular North Coordinate
A = Azimuth
D = Distance
==================
EXPORT P2RN(A,D)
BEGIN
//

LOCAL N;
N:=COS(A)*D;

RETURN N;

END;
==================

what am I doing wrong?

Your entire program is viewed as a comment, and hence doesn't execute. If you remove the "====" in both places, and remove the "//" to uncomment the program, it runs fine. This is more clearly seen (in the conn kit), if you copy / paste the code you've shown here, into the emulator over a "new" P2RN Program.

Conversely, you can keep the ==='s if you place "//" comment symbols before them, accordingly:
Code:

// ==============

EXPORT P2RN(A,D)
BEGIN


LOCAL N;
N:=COS(A)*D;

RETURN N;

END;

//============
Find all posts by this user
Quote this message in a reply
12-12-2014, 08:44 AM
Post: #10
RE: Calling a Program from Home Page. What's Wrong
The "====" where not actually in the program.
I just cosmetically added them in my posting, sorry.
According to the manual the "\\" only comment out the line they are on.
There is no end-of-line ";" required either.
_______

"Is there any other program on your calc which has defined an exported variable or function named "P2RN"? You may try the full name: <PROGNAME>.P2RN(...).
"

No
_______

"Did you try 'restart' to clear vars? Also, (after an emulator back up): Calculator | Reset, may be helpful."

I'll try that next. "Check for update" didn't find anything.
The place to see where to find the firmware version on my calculator is apparently in
Connectivity Pgm, HP-Prime, Properties?
Application Version = 20131125 v5447
Operating System Version = V0.030.5447

Emulator
Application Version = 20130331 v6031

Searched the User Manual for "Version" and "firmware" didn't see anything relevant.
So can't do it on calculator.

Just today something weird happened. Apparently the calculator had some sort of crash and locked up. I used a pin to reset it. All programs were still there. What was unusual was the Booting Screen was one I had not seen before.
I was an artistically rendered/printed equation something like "x2 + y2 = r2"
The background was a grid pattern.
Also, I think some of the programs I'd deleted or renamed came back.
_______

Am I correct in saying there is no way to copy ALL programs on the physical calculator, en masse, over to the Virtual Calculator? And vice-versa.
(click first-file / shift-click last-file / Copy / Paste to Folder)
That I have to Create/Copy/Paste each one-at-a-time?
_______

Still trying to find a way to Export a Spreadsheet and/or Matrix to my PC via the Connectivity Program.
Maybe even as a simple ASCII CSV file.
(click first-cell / shift-click last-cell / Copy / Paste to into Text Editor or Excel on PC)
_______

One good thing is that all this is very mentally absorbing.
Sorry for all the questions.
Find all posts by this user
Quote this message in a reply
12-12-2014, 12:25 PM
Post: #11
RE: Calling a Program from Home Page. What's Wrong
If, in the conn kit, you see your physical device, just create a 'back up' the physical device. Then, on the virtual device, you can 'restore' from that (physical device) 'back up' file just created.

Quote:The "====" where not actually in the program.
I just cosmetically added them in my posting, sorry.
According to the manual the "\\" only comment out the line they are on.
There is no end-of-line ";" required either.

After I copy/pasted the code (from your first post) into the virtual calc, via the conn kit, your entire program was a single comment line. This may be an artifact from the way it was posted, but, as such, it does not run.

As to why P2RN(45,100) failed, after removing the "====" surrounding the program, as well as the "//", the program compiled without error. P2RN(45,100) worked fine on the virtual calc.

Hopefully, you've discovered the problem and moved on.
Find all posts by this user
Quote this message in a reply
12-12-2014, 01:00 PM (This post was last modified: 12-12-2014 01:21 PM by Snorre.)
Post: #12
RE: Calling a Program from Home Page. What's Wrong
(12-12-2014 08:44 AM)bobkrohn Wrote:  According to the manual the "\" only comment out the line they are on.
Correct (but "//" instead of "\\").

(12-12-2014 08:44 AM)bobkrohn Wrote:  There is no end-of-line ";" required either.
Correct, trailing ";" is required only for statements (and can be omitted for an expressions if it's the last within a block).

(12-12-2014 08:44 AM)bobkrohn Wrote:  Searched the User Manual for "Version" and "firmware" didn't see anything relevant.
So can't do it on calculator.
Press "Help" button, then softmenu "Tree", then treeitem "About HP Prime", and finally softmenu "OK". You'll see the software version: <date> (<build number>).

(12-12-2014 08:44 AM)bobkrohn Wrote:  I was an artistically rendered/printed equation something like "x2 + y2 = r2"
The background was a grid pattern.
That's normal while restarting. You should have seen this picture the first time You switched on Your newly bought device.

(12-12-2014 08:44 AM)bobkrohn Wrote:  Am I correct in saying there is no way to copy ALL programs on the physical calculator, en masse, over to the Virtual Calculator? And vice-versa.
(click first-file / shift-click last-file / Copy / Paste to Folder)
That I have to Create/Copy/Paste each one-at-a-time?
No, in Connectivity Kit right-click on your source device, select "copy from here", right-click on your target device, select "copy to here". After that, both devices should contain the same data (history, apps, programs, vars, notes etc.).

(12-12-2014 08:44 AM)bobkrohn Wrote:  Still trying to find a way to Export a Spreadsheet and/or Matrix to my PC via the Connectivity Program.
Maybe even as a simple ASCII CSV file.
(click first-cell / shift-click last-cell / Copy / Paste to into Text Editor or Excel on PC)
Open Your spreadsheet in Connectivity Kit, select the whole sheet, copy, paste into Excel. You'll lose the formatting and may need to correct some function names or decimal signs (in my case Excel functions have German names like "SUMME" instead of "SUM", and numbers have an other decimal sign). Some spreadsheet objects and functions (e.g. complex numbers, matrices within cells, CAS-functions) may not work in Excel.

(12-12-2014 08:44 AM)bobkrohn Wrote:  Sorry for all the questions.
You're welcome.
Find all posts by this user
Quote this message in a reply
12-18-2014, 07:14 AM
Post: #13
RE: Calling a Program from Home Page. What's Wrong
Just upgraded to the new firmware. Dec 03 2014

Still has the bug with using a number in a Function name (unless it's the last character)

Yup absolutely a valid bug.
Find all posts by this user
Quote this message in a reply
12-18-2014, 12:41 PM (This post was last modified: 12-18-2014 12:44 PM by Snorre.)
Post: #14
RE: Calling a Program from Home Page. What's Wrong
Hi Bobkrohn,

I could reproduce the error you described.
This occurres if the current app is "Spreadsheet": "P2RN(A,D)" throws an error since "P2RN" is interpreted as "P2*R*N" (as if P2 was a cell name).
If I choose another app (e.g. "Functions"): "P2RN(A,D)" will call the so named program function.

Could you check that on your device?
Find all posts by this user
Quote this message in a reply
12-18-2014, 02:49 PM
Post: #15
RE: Calling a Program from Home Page. What's Wrong
(12-18-2014 12:41 PM)Snorre Wrote:  I could reproduce the error you described.
This occurres if the current app is "Spreadsheet": "P2RN(A,D)" throws an error since

If you are correct, then looks like implicit multiplication has reared its ugly head again... :-(

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
12-18-2014, 09:37 PM (This post was last modified: 12-18-2014 09:41 PM by Gilles.)
Post: #16
RE: Calling a Program from Home Page. What's Wrong
(12-18-2014 02:49 PM)Tim Wessman Wrote:  
(12-18-2014 12:41 PM)Snorre Wrote:  I could reproduce the error you described.
This occurres if the current app is "Spreadsheet": "P2RN(A,D)" throws an error since

If you are correct, then looks like implicit multiplication has reared its ugly head again... :-(

It works fine for me with the rev 6975 both with virtual and real calc.

EDIT:Same as Snore, I get an error if the current app is "Spreadsheet"
Find all posts by this user
Quote this message in a reply
12-18-2014, 11:25 PM
Post: #17
RE: Calling a Program from Home Page. What's Wrong
[Home View] Spreadsheet app, P2RN(45,100) returns syntax error. Cursor just inside opening paren.
Find all posts by this user
Quote this message in a reply
12-19-2014, 05:18 AM
Post: #18
RE: Calling a Program from Home Page. What's Wrong
You have Sharp Eyes Snorre!
I would never have figured that out.
Yes, I have Spreadsheet active.
Find all posts by this user
Quote this message in a reply
12-19-2014, 03:29 PM
Post: #19
RE: Calling a Program from Home Page. What's Wrong
(12-19-2014 05:18 AM)bobkrohn Wrote:  Yes, I have Spreadsheet active.

Ok, now that you've isolated a root cause I've put this on the list of things to look at.

Thanks!

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
Post Reply 




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