Post Reply 
IFERR? Interception of an input error
03-10-2017, 08:25 AM (This post was last modified: 03-10-2017 09:01 AM by Onieh.)
Post: #1
IFERR? Interception of an input error
Hello,
I would not want which falls that programme if I ENTER presses without giving before 4 letters.
for example, EDUS or EDAX etc.
Even if I figures give the programme should not fall, sonder as long as wait to me 4 letters has given.

Addition: if I enter four letters and the is not there, the program should not crash, but the MSGBOX notify that the letters are not in the spreadsheet! i.e. ABCD

EXPORT Navigation()
BEGIN
LOCAL I,A,B,C,D,E,F,G;
LOCAL H;

STARTAPP("Flugplatz");

INPUT({{H,[2]}},"Flugplatzkennung"); //INPUT Airfield i.e. EDUS

RECT_P(0,0,320,240,RGB(0,205,205));

I:=POS(a:a,H);

TEXTOUT_P("F l u g p l a t z",90,0,7);

RECT_P(0,32,320,34);

TEXTOUT_P((EXPR("A"+I)),90,40,4);
TEXTOUT_P((EXPR("B"+I)),90,70,4);
TEXTOUT_P((EXPR("C"+I)),90,100,4);
TEXTOUT_P((EXPR("D"+I)),90,130,4);
TEXTOUT_P((EXPR("E"+I)),90,160,4);

WAIT();
FREEZE;

STARTVIEW (-1);
END;
Find all posts by this user
Quote this message in a reply
03-10-2017, 12:47 PM
Post: #2
RE: IFERR? Interception of an input error
(03-10-2017 08:25 AM)Onieh Wrote:  INPUT({{H,[2]}},"Flugplatzkennung"); //INPUT Airfield i.e. EDUS

Sorry, Dein Englisch verstehe ich nicht :/
Aus dem Source schliesse ich auf Deutsch als Ursprung.
Beschreib das mal bitte in Deutsch?

P.S. "Flugplatzkennung" mit 4 Zeichen? IATA sind üblicherweise 3 ?
Find all posts by this user
Quote this message in a reply
03-10-2017, 01:01 PM
Post: #3
RE: IFERR? Interception of an input error
(03-10-2017 12:47 PM)EdDereDdE Wrote:  
(03-10-2017 08:25 AM)Onieh Wrote:  INPUT({{H,[2]}},"Flugplatzkennung"); //INPUT Airfield i.e. EDUS

Sorry, Dein Englisch verstehe ich nicht :/
Aus dem Source schliesse ich auf Deutsch als Ursprung.
Beschreib das mal bitte in Deutsch?

P.S. "Flugplatzkennung" mit 4 Zeichen? IATA sind üblicherweise 3 ?

Hallo, sorry mein Englisch ist nicht so gut.
Also, sofern die Flugplatzkennung, das sind in der Regel 4 Buchstaben, z.B. EDAX noch nicht eingegeben worden sind und man Enter druck stürzt das Programm ab. Das gleich gilt wenn ich Zahlen eingebe. Ich benötige eine Routine, die erst dann im Programm weiter mach, wenn die Kennung richtig eingegeben worden ist.
Sollte jedoch ABCD eingegeben werden, soll eine Dialogbox erscheinen, die besagt, dass es diese Kennung nicht gibt.
Find all posts by this user
Quote this message in a reply
03-10-2017, 02:01 PM
Post: #4
RE: IFERR? Interception of an input error
Naja, das ist wie bei einem PC-Programm:
Du bettest den Input in eine Schleife ein, die solange nicht verlasssen wird, wie die Eingabe nicht im erwarteteten Rahmen liegt.

Abstract:

PHP Code:
OK := 0;
REPEAT
   INPUT 
(H, ...);
   
// Plausibilitätsprüfungen ...
   
IF DIM(H) == 4 THEN
      
// Special Test "ABCD" ...
      
IF == "ABCD" THEN
         MSGBOX
("Invalid!");
      ELSE
         IF 
is_numeric(HTHEN
             MSGBOX
("Numeric");
         ELSE
           
OK := 1;
         
END;
      
END
   END
;
UNTIL OK
mit Funktion ala:
PHP Code:
is_numeric(H)
BEGIN
   LOCAL c
num := 0;
   FOR 
c FROM 1 TO DIM(H) DO
      
num := POS({47,48,49,50, ..., 57},ASC(H(c)));
      IF 
num THEN CONTINUE; END;
   
END;
   RETURN 
num;
END
Find all posts by this user
Quote this message in a reply
03-10-2017, 02:25 PM
Post: #5
RE: IFERR? Interception of an input error
(03-10-2017 02:01 PM)EdDereDdE Wrote:  Naja, das ist wie bei einem PC-Programm:
Du bettest den Input in eine Schleife ein, die solange nicht verlasssen wird, wie die Eingabe nicht im erwarteteten Rahmen liegt.

Abstract:

PHP Code:
OK := 0;
REPEAT
   INPUT 
(H, ...);
   
// Plausibilitätsprüfungen ...
   
IF DIM(H) == 4 THEN
      
// Special Test "ABCD" ...
      
IF == "ABCD" THEN
         MSGBOX
("Invalid!");
      ELSE
         IF 
is_numeric(HTHEN
             MSGBOX
("Numeric");
         ELSE
           
OK := 1;
         
END;
      
END
   END
;
UNTIL OK
mit Funktion ala:
PHP Code:
is_numeric(H)
BEGIN
   LOCAL c
num := 0;
   FOR 
c FROM 1 TO DIM(H) DO
      
num := POS({47,48,49,50, ..., 57},ASC(H(c)));
      IF 
num THEN CONTINUE; END;
   
END;
   RETURN 
num;
END

Danke, ich werde das mal ausprobieren.
Das mit dem ABCD war nur ein Beispiel. Kann auch cccc od. fefe od. tttt, etc, sein.
Auf jeden Fall ein Ausdruck der nicht im Spreadsheet enthalten ist!
Im Spreadsheet fangen die meisten mit ED.. an, z. B. EDKA od. EDHO, oder EDBT, etc.
Find all posts by this user
Quote this message in a reply
03-10-2017, 03:08 PM
Post: #6
RE: IFERR? Interception of an input error
(03-10-2017 02:01 PM)EdDereDdE Wrote:  
PHP Code:
is_numeric(H)
BEGIN
   LOCAL c
num := 0;
   FOR 
c FROM 1 TO DIM(H) DO
      
num := POS({47,48,49,50, ..., 57},ASC(H(c)));
      IF 
num THEN CONTINUE; END;
   
END;
   RETURN 
num;
END

There is a bug in your code. Num would be non-zero as long as the last character is numeric. Your IF statement should be: IF (num == 0) THEN RETURN(0); END;

There is no need for CONTINUE, since there is no code to skip after the IF statement. In fact, the current IF statement doesn't actually do anything when you trace the logic.

Also, as an alternative to POS(), you could use: num:=(ASC(H(c)) > 46) AND (ASC(H(c)) < 58);

(The latter suggestion is only pertinent for speed, and when testing for a larger range since POS() could in theory check all the way to the last item in the list.)

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
03-10-2017, 04:39 PM
Post: #7
RE: IFERR? Interception of an input error
Here is a way to control the input to be only 4 letters within the spreadsheet. If you enter 4 letters that are not found in the spreadsheet they will turn red and you have to press the Del key to fix your entry.

PHP Code:
EXPORT Navigation()
BEGIN
LOCAL I
,A,B,C,D,E,F,G;
LOCAL H,K,Letter;
LOCAL Keys:={"-","-","-","-","-",
"-","-","-","-",
"-","-","-","-","-",
"A","B","C","D","E","Del",
"F","G","H","I","J","K",
"L","M","N","O","-",
"P","Q","R","S","T",
"-","U","V","W","X",
"-","Y","Z","-","-",
"-","-","-","-","-"};

STARTAPP("Flugplatz");

RECT_P(0,0,320,240,RGB(0,205,205));       //Clear screen

TEXTOUT_P("F l u g p l a t z",90,0,7);

H:=""I:=0;
WHILE 
I<OR POS(a:a,H)==DO            //Loop until we got 4 letters that are in the spreadsheet
 
Letter:="-";
 WHILE 
Letter=="-" DO                    //Loop until a letter or the Del key is pressed
   
K:=0
   WHILE 
K=DO K:=WAIT()+1END;      //Wait until a key is pressed and get the key code
   
Letter:=Keys(K);                      //Convert the keycode to a letter
 
END;
 IF 
Letter=="Del" THEN                   //If Del key has been pressed, clear text and remove one letter from H 
   
IF I>0 THEN TEXTOUT_P(H,90,40,4,RGB(0,205,205),90,RGB(0,205,205));IFTE(I=1,H:="",H:=LEFT(H,I-1));I:=I-1END;
 ELSE                                    
//Else it's a letter, 
   
IF I<4 THEN H:=H+Letter;I:=I+1END;  // add it to H and increase the number of letters if we have not yet 4 letters
 
END;
 IF 
I==AND POS(a:a,H)==0 THEN          //If we have 4 letters that are not in the spreadsheet ...
   
TEXTOUT_P(H,90,40,4,RGB(255,0,0),90,RGB(0,205,205));  // ... then print them in RED ...
 
ELSE
   
TEXTOUT_P(H,90,40,4);                 // .. else print current letters in black
 
END;
END;

I:=POS(a:a,H);

RECT_P(0,32,320,34);

//TEXTOUT_P((EXPR("A"+I)),90,40,4);
TEXTOUT_P((EXPR("B"+I)),90,70,4);
TEXTOUT_P((EXPR("C"+I)),90,100,4);
TEXTOUT_P((EXPR("D"+I)),90,130,4);
TEXTOUT_P((EXPR("E"+I)),90,160,4);

WAIT();
FREEZE;

STARTVIEW (-1);
END
Find all posts by this user
Quote this message in a reply
03-10-2017, 05:06 PM
Post: #8
RE: IFERR? Interception of an input error
(03-10-2017 04:39 PM)Didier Lachieze Wrote:  Here is a way to control the input to be only 4 letters within the spreadsheet. If you enter 4 letters that are not found in the spreadsheet they will turn red and you have to press the Del key to fix your entry.

PHP Code:
EXPORT Navigation()
BEGIN
LOCAL I
,A,B,C,D,E,F,G;
LOCAL H,K,Letter;
LOCAL Keys:={"-","-","-","-","-",
"-","-","-","-",
"-","-","-","-","-",
"A","B","C","D","E","Del",
"F","G","H","I","J","K",
"L","M","N","O","-",
"P","Q","R","S","T",
"-","U","V","W","X",
"-","Y","Z","-","-",
"-","-","-","-","-"};

STARTAPP("Flugplatz");

RECT_P(0,0,320,240,RGB(0,205,205));       //Clear screen

TEXTOUT_P("F l u g p l a t z",90,0,7);

H:=""I:=0;
WHILE 
I<OR POS(a:a,H)==DO            //Loop until we got 4 letters that are in the spreadsheet
 
Letter:="-";
 WHILE 
Letter=="-" DO                    //Loop until a letter or the Del key is pressed
   
K:=0
   WHILE 
K=DO K:=WAIT()+1END;      //Wait until a key is pressed and get the key code
   
Letter:=Keys(K);                      //Convert the keycode to a letter
 
END;
 IF 
Letter=="Del" THEN                   //If Del key has been pressed, clear text and remove one letter from H 
   
IF I>0 THEN TEXTOUT_P(H,90,40,4,RGB(0,205,205),90,RGB(0,205,205));IFTE(I=1,H:="",H:=LEFT(H,I-1));I:=I-1END;
 ELSE                                    
//Else it's a letter, 
   
IF I<4 THEN H:=H+Letter;I:=I+1END;  // add it to H and increase the number of letters if we have not yet 4 letters
 
END;
 IF 
I==AND POS(a:a,H)==0 THEN          //If we have 4 letters that are not in the spreadsheet ...
   
TEXTOUT_P(H,90,40,4,RGB(255,0,0),90,RGB(0,205,205));  // ... then print them in RED ...
 
ELSE
   
TEXTOUT_P(H,90,40,4);                 // .. else print current letters in black
 
END;
END;

I:=POS(a:a,H);

RECT_P(0,32,320,34);

//TEXTOUT_P((EXPR("A"+I)),90,40,4);
TEXTOUT_P((EXPR("B"+I)),90,70,4);
TEXTOUT_P((EXPR("C"+I)),90,100,4);
TEXTOUT_P((EXPR("D"+I)),90,130,4);
TEXTOUT_P((EXPR("E"+I)),90,160,4);

WAIT();
FREEZE;

STARTVIEW (-1);
END

Wow, it's a very good INPUT.
Thank you very much!!!
Find all posts by this user
Quote this message in a reply
03-10-2017, 07:51 PM
Post: #9
RE: IFERR? Interception of an input error
(03-10-2017 03:08 PM)Han Wrote:  There is a bug in your code. Num would be non-zero as long as the last character is numeric. Your IF statement should be: IF (num == 0) THEN RETURN(0); END;

There is no need for CONTINUE, since there is no code to skip after the IF statement. In fact, the current IF statement doesn't actually do anything when you trace the logic.

Right Han, i was meaning "BREAK", but a direct RETURN works as well.
I was typing this "on the go" on my tablet, neither on Emulator nor "real" calculator Smile
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: