Post Reply 
Unexxpected Procedure Call (Solved) when variable undefine
11-15-2016, 10:43 PM (This post was last modified: 11-25-2016 12:09 PM by StephenG1CMZ.)
Post: #1
Unexxpected Procedure Call (Solved) when variable undefine
In this program, when I forget to define variable KK (it was defined until I split the procedure into two procedures, one omitted here), Running the program seems to execute a WAIT, and when I tap ESC an "ESCAPE" MSGBOX appears.
The KIF MSGBOX only appears if the variable is defined.

Code:

 
 
 EXPORT Precision10 (JJ)
 BEGIN
  //LOCAL KK:=LOG(2);
  MSGBOX(KK);
  PRINT(JJ+": "+(JJ*KK));//NUM OF DEC DIGITS ACCURACY
  //RESULT IS REAL,TRIG MAYBE WORSE
 END;

 EXPORT PREC()
 BEGIN
  PRINT();
  Precision10(53);
MSGBOX("KIF");

 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-16-2016, 06:15 AM
Post: #2
RE: Unexpected Escape when variable undefined
Hello,

I defined KK in home.
Then I entered your program.
Then I deleted KK from home.
then I ran the program.

I got the expected "Error: Unmatched control word" error.

Is that not what you are seeing?

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-16-2016, 08:53 AM (This post was last modified: 11-16-2016 09:03 AM by StephenG1CMZ.)
Post: #3
RE: Unexpected Escape when variable undefined
Here is what I see when I run the program and tap ESC.

I did write some code a few months ago that waited for a keypress and MSGBOXed ESCAPE, whilst debugging some other program. But if I tap something other than ESC I get the system "!", whereas my old code would have ignored other keypress or printed the ASCII code.

The code here originally measured the available precision in bits, then multiplied by log(2) to show decimal digits of precision. That worked, but I decided to separate the bit-measuring into a separate procedure and accidentally had the LOCAL KK in the wrong procedure - and the program began waiting for an ESC. Defining KK in the correct procedure fixed that.

It might be relevant that for some time now, my Android phone has been warning that it is running out of storage space.


Attached File(s) Thumbnail(s)
   

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-24-2016, 10:31 PM (This post was last modified: 11-25-2016 04:56 PM by StephenG1CMZ.)
Post: #4
RE: Unexpected Escape when variable undefined (SOLVED...My mistake)
Oh, how silly of me.
I wasn't expecting that ESCAPE to print, and Android had been telling me things might not work correctly as I am running out of storage space.
In my defence, I have seen other platforms sometimes jumble up file contents into the wrong files.

I remembered writing a couple of lines of code to print ESCAPE, as part of some other program, but remembered it as just a couple of lines of in-line code whilst testing key handling - so didn't think it should execute.

Enough excuses.

The code had actually been written as an exported procedure, named KK!
So when variable KK was not defined...procedure KK executed.

I've no idea why I wrote that as a procedure - but when you start a procedure using the templates, the only option is to make an export function. There is no template for local functions. If I had made it local, it wouldn't have been seen. Template/Function/Export only.

But the main way to avoid such confusion between variables and procedure calls, would be to require a pair of () after the KK to see it as a procedure call.
Code:


 //KK
 EXPORT KK()
 BEGIN
  LOCAL KK;
  //MSGBOX(STRING(K_Esc));
  WHILE 1 DO
   KK:=GETKEY();
   IF KK≠−1 THEN
    PRINT(KK);
    IF KK==4 THEN
     MSGBOX("ESCAPE");
    END;
   END; 
  END;
 
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




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