Post Reply 
User tabs
04-09-2019, 05:31 PM (This post was last modified: 04-11-2019 04:45 AM by Gene222.)
Post: #1
User tabs
I am trying to learn how to write programs with user tabs. In the program below, I can create a user tab to rerun the program, but I cannot create a tab to exit the program. When I press the exit tab, the program still shows the print terminal, and I have to press the Esc key to return to the Home screen. How can I cleanly exit the program without having to press the esc key?

PHP Code:
EXPORT Menu_Example_2()  //main program
BEGIN 

  LOCAL m
m1mxmy;   //tab variables
  
LOCAL x,y,z;           //input variables

  
INPUT( { {x,[0],{24,18,2}},
           {
y,[0],{24,18,3}},
           {
z,[0],{24,18,4}}},
         
"Menu Input Example",
         { 
"x = ",
           
"y = ",
           
"z = "});

  
//write to the print terminal
  
PRINT();             //clears terminal print buffer
  
PRINT("x = "+x);     //writes to terminal print buffer
  
PRINT("y = "+y);
  PRINT(
"z = "+z);

  
DRAWMENU("x""repeat""exit1""tab 4""tab 5""tab 6");  //draws tabs on the screen

  
WAIT(1);  //displays print terminal screen with the user tabs, pauses for 1 second waiting for a command.
            //after one second, print terminal screen is still displayed (or active), and program continues.

  
REPEAT 
    m 
:= MOUSE;         //MOUSE pauses the program
                        //displays the print terminal screen waiting for a tap on the screen
                        //when the screen is tapped, returns list of tap coordinates {{x1,y1},(x2,y2}...}
    
m1 := m(1);         //stores first element of the list {x1,y1} into m1
  
UNTIL SIZE(m1) > 0;   //exit loop when tap coordinates are found

  
mx := m1(1);          //store x1 coordinate
  
my := m1(2);          //store y1 coordinate

  
IF my ≥ 220 AND my ≤ 239 THEN          //is y1 coordinate between 220 and 239?

    
IF mx ≥ 0 AND mx ≤ 51 THEN           //Is tab 1 x coordinate found?
      
RETURN ("tab 1 was pressed "+x);      //returns text and number to the command line, but displays
                                            //print terminal screen.  User must press Esc key
    
END;                                    //to return to Home or program catalog screen.
    
    
IF mx ≥ 53 AND mx ≤ 104 THEN         //Is tab 2 x coordinate found?
      
Menu_Example_2();                     //Run the main program again
                                            //Contents of variables x,y,z were cleared.
    
END;

    IF 
mx ≥ 106 AND mx ≤ 157 THEN        //Is tab 3 x coordinate found?
      
RETURN;                               //displays print terminal screen.  
                                            //User must press Esc key to return to Home or program catalog screen.                               
    
END;                                    

    IF 
mx ≥ 159 AND mx ≤ 210 THEN 
      
//no action
    
END;

    IF 
mx ≥ 212 AND mx ≤ 263 THEN 
      
//no action
    
END;

    IF 
mx ≥ 265 AND mx ≤ 319 THEN 
      
//no action
    
END;

  
END;

END//end of program 


A revised program is shown below. I still can't cleanly exit the program with a single tap and return to the Home screen. Also, when repeating the program several times and then pressing the exit 2 tab, the WAIT period seems to be cumulative. The row of user tabs blocks any underlying text on the terminal screen. One cannot scroll the text up or down, while the user tabs are displayed.

PHP Code:
EXPORT UserTabs2()  //main program
BEGIN 

  LOCAL m
m1mxmy;   //tap variables
  
LOCAL x,y,z,z1;        //input variables and counter z1
  
LOCAL total,sum_xy;

  
z1:=0;  //zero WHILE loop counter or flag variable

  
INPUT( { {x,[0],{24,18,2}},
           {
y,[0],{24,18,3}},
           {
z,[0],{24,18,4}}},
         
"User Tabs Input Example",
         { 
"x = ",
           
"y = ",
           
"z = "});

  
//write to the print terminal
  
PRINT();             //clears print terminal buffer
  
PRINT("x = "+x);     //writes to print terminal buffer
  
PRINT("y = "+y);
  PRINT(
"z = "+z);

  
//This WHILE loop will repeat the tap procedure, until the user presses one of the active tabs.
  //After which, the tab procedures end the program.
  
WHILE z1==DO

    
DRAWMENU("x""repeat""exit""exit 2""total""Σxy");  //draws tabs on the screen
                                                                //these tabs are just pictures and have no special features.
    
WAIT(1);  //Displays print terminal screen with the user tabs, pauses for 1 second 
              //waiting for a command.  After one second, print terminal screen is still 
              //displayed (or active), and program continues.
              //WAIT(-1) will return in 60 sec OR a key or a mouse event.
  
    // This REPEAT-UNTIL loop will fetch the screen tap coordinates.  The screen tap 
    // coordinates can be within one of the user tabs, or outside of the user tabs,
    // such as in the middle of the screen.
    
REPEAT 
      m 
:= MOUSE;         //MOUSE pauses the program
                          //Displays the print terminal screen waiting for a tap on the screen
                          //When the screen is tapped, returns list of tap coordinates {{x1,y1},(x2,y2}...}
      
m1 := m(1);         //stores first element of the list {x1,y1} into m1
    
UNTIL SIZE(m1) > 0;   //exit loop when tap coordinates are found

    
mx := m1(1);          //store x1 coordinate
    
my := m1(2);          //store y1 coordinate

    // These nested IF statements check to see if the tap was within the user tab
    
IF my ≥ 220 AND my ≤ 239 THEN          //Was the screen tap within the row of user tabs?

      
IF mx ≥ 0 AND mx ≤ 51 THEN           //Was tab 1 pressed?
        
z1:=1;                             //flag to exit loop
        
RETURN ("tab 1 was pressed "+x);   //returns text and number to the Home screen, but displays
      
END;                                 //print terminal screen.  User must press Esc key to return to Home
    
      
IF mx ≥ 53 AND mx ≤ 104 THEN         //Was tab 2 pressed?
        
UserTabs2();                       //Runs the main program again, Variables x,y,z are cleared.
      
END;

      IF 
mx ≥ 106 AND mx ≤ 157 THEN        //Was tab 3 pressed?
        
z1:=1;                             //flag to exit loop  
        
RETURN;                            //WAIT(1) seems to be accumulative when repeating the program several times                
      
END;                                 //before pressing the exit tab

      
IF mx ≥ 159 AND mx ≤ 210 THEN        //Was tab 4 pressed?
        
z1:=1;                             //flag to exit loop
        
PRINT(" ");
        PRINT(
"x1 coordinate (mx) = "+mx);
        PRINT(
"y1 coordinate (my) = "+my);
        PRINT(
"while loop counter (z1) = "+z1);
        PRINT(
"Press Esc key to exit");
      
END;

      IF 
mx ≥ 212 AND mx ≤ 263 THEN        //Was tab 5 pressed?
        
total:=x+y+z;
        PRINT(
" ");
        PRINT(
"total = "+total);
      
END;

      IF 
mx ≥ 265 AND mx ≤ 319 THEN        //Was tab 6 pressed?
        
sum_xy:=x+y
        PRINT();             
//clear print terminal
        
PRINT("x = "+x);     
        PRINT(
"y = "+y);
        PRINT(
"z = "+z);
        PRINT(
"sum of x and y = "+sum_xy);
      
END;

    
END// nested IF statements

  
END  // WHILE loop

END//main program
     //When the program ends, the print terminal is displayed.
     //User must press Esc key to return to Home screen 
Find all posts by this user
Quote this message in a reply
04-10-2019, 10:29 PM (This post was last modified: 04-12-2019 10:41 PM by Gene222.)
Post: #2
RE: User tabs
The user tabs seems to work better on the Home screen than on the print terminal screen. The UserTabs4 program below needs to be launched from the Home screen, such as by the Toolbox key and User tab. The program will draw the tabs on the Home screen. Selecting the "x+y" tab adds the two numbers and RETURNs the answer to the Home screen. The user does not have to select the exit tab or press the Esc key like on the previous program. I am guessing that the DRAWMENU and/or WAIT commands draws the user tabs on the current active screen, whether it is the Home screen or print terminal screen. I should mention that the screen shot is the Home screen in program mode. It is not the Home screen in the normal calculation mode. The tabs will only be shown when the program is running.

(added 4/11/19) User tab 4 is x^2. It prints the answer to the print terminal. The last line of the tab 4 procedures is RETURN(sq_x). The RETURN command seems to be needed to display the print terminal. The user must press the Esc key to exit the print terminal and return to the Home screen. The RETURN command also seems to be needed to return the answer to the Home screen by including sq_x in the parenthesis.

[Image: nvd5jm.png]

UserTabs4 code. (revised 4/12/19)

PHP Code:
EXPORT UserTabs4()
//This program will draw user tabs on the Home screen

BEGIN 

  LOCAL m
,m1,mx,my,z1,n;      //tap variables and counters
  
LOCAL x,y,z;                //input variables
  
LOCAL total,sum_xy,prod_xy,sq_x;

  
z1:=0;  //zero WHILE loop counter

  //This WHILE loop will repeat the tap procedures, until the user presses one of the active tabs.
  //After which, the program runs the tab procedures; and where, the program ends by using the RETURN command.
  
WHILE z1==DO

    
STARTVIEW(-1,1);  //displays the home screen and refreshes the display.
                      //This is needed if the program is launched from the program catalog.
                      //It would change the active screen from the program catalog screen to the home screen

    
DRAWMENU("total""x+y""x*y""x^2""""exit"); //Draws the tabs on the active screen.
                                                        //These tabs are just pictures 
                                                        //and have no special features.
    
WAIT(1);  //Displays the Home screen with the user tabs, and pauses for 1 second. 
              //During the pause, key presses and screen taps are ignored.
              //After one second, the Home screen is still displayed (or active), and the program continues.
              //The WAIT(n) command can be made to return n, or 1 as used here, but the return is not used 
              //in this program.  To use the return, the statement would need to be written as n:=WAIT(1);
              //The command WAIT(-1) will wait 60 seconds, but the pause can be interrupted by a key press 
              //or screen tap.  The command WAIT(-1) requires different program code then used here.  
              //It can be made to return the key code or mouse coordinates.
  
    // This REPEAT-UNTIL loop will fetch the screen tap coordinates.  The screen tap 
    // coordinates can be for a tap within one of the user tabs, or outside of the user tabs,
    // such as in the middle of the screen.
    
REPEAT 
      m 
:= MOUSE;         //MOUSE pauses the program and waits for a tap on the screen. Key presses are ignored.
                          //When the screen is tapped, returns list of tap coordinates and other info
      
m1 := m(1);         //Stores first element of the list of tap coordinates {x1,y1,x2,y2,?}
                          //An example of m1 is {#77:-16d,#229:-16d,#77:-16d,#229:-16d,#1:16d}
    
UNTIL SIZE(m1) > 0;   //exits the loop when tap coordinates are found

    
mx := m1(1);          //Stores x1 tap coordinate. An example of mx is #77:-16d, where 77 is the x coordinate
    
my := m1(2);          //Stores y1 tap coordinate. An example of my is #229:-16d, where 229 is the y coordinate

    // These nested IF statements check to see if the tap was within the user tab
    
IF my ≥ 220 AND my ≤ 239 THEN          //Was the screen tap within the row of user tabs?

      
IF mx ≥ 0 AND mx ≤ 51 THEN           //Was tab 1 "total" pressed?
        
INPUT({{x,[0],{24,18,2}},
               {
y,[0],{24,18,3}},
               {
z,[0],{24,18,4}}},
              
"User Tabs Input Example",
              {
"x = ",
               
"y = ",
               
"z = "});
        
total:=x+y+z;
        RETURN(
total);                            
      
END;
    
      IF 
mx ≥ 53 AND mx ≤ 104 THEN         //tab 2 "x+y"
        
INPUT({{x,[0],{24,18,2}},
               {
y,[0],{24,18,3}},
               {
z,[0],{24,18,4}}},
              
"User Tabs Input Example",
              {
"x = ",
               
"y = ",
               
"z = "});       
        
sum_xy:=x+y;
        RETURN(
sum_xy);
      
END;

      IF 
mx ≥ 106 AND mx ≤ 157 THEN        //tab 3 "x*y"
        
INPUT({{x,[0],{24,18,2}},
               {
y,[0],{24,18,3}},
               {
z,[0],{24,18,4}}},
              
"User Tabs Input Example",
              {
"x = ",
               
"y = ",
               
"z = "});
        
prod_xy:=x*y;
        RETURN(
"x*y = "+prod_xy);           
      
END;

      IF 
mx ≥ 159 AND mx ≤ 210 THEN        //tab 4 "x^2"
        
INPUT(x);
        
sq_x:=x^2;
        PRINT();                           
//clears the print terminal
        
PRINT("x^2 = "+sq_x);              //writes to the print terminal
        
RETURN(sq_x);                      //The RETURN serves two functions, It ends the program and allows
      
END;                                 //print terminal to be displayed. It also returns the answer 
                                           //to the home screen.  The user must press the Esc key 
                                           //to switch back to the Home screen.

      
IF mx ≥ 212 AND mx ≤ 263 THEN        //tab 5
        //no action
      
END;

      IF 
mx ≥ 265 AND mx ≤ 319 THEN        //tab 6 "exit"
        
RETURN;
      
END;

    
END// nested IF statements

  
END;  // WHILE loop

END//main program 
Find all posts by this user
Quote this message in a reply
04-11-2019, 04:58 PM (This post was last modified: 04-18-2019 10:07 PM by Gene222.)
Post: #3
RE: User tabs
Revised 4/14/19. In the previous program, the exit tab does not work. The RETURN command will not exit to the Home screen. I could not find any way to exit the program and return to the Home screen. So, the program was changed to draw the user tabs on the G0 graphics screen. In the program below the STARTVIEW(-1,1) command was replaced with a RECT() command. RECT() will clear the G0 graphic screen and make it the current active screen. DRAWMENU then draws the tabs on the G0 screen, and MOUSE displays the G0 screen, and waits for a tap. When the exit tab is pressed, the RETURN command will exit the program and switch back to the Home screen. This is the only way I could make the exit tab work.

The WAIT commanded used in the previous program was not necessary. The MOUSE command will display the current screen (in this case it is the G0) with the tabs shown. The program below shows the user tab program with the WAIT command deleted.

Revised (4/18/19) program with the WAIT statement deleted and uses the G0 screen.

PHP Code:
EXPORT UserTabs9a()
//This program will draw user tabs on the G0 screen.  All results are returned to the Home screen or print terminal.

BEGIN 

  LOCAL m
,m1,mx,my,z1,n;      //tap variables and counters
  
LOCAL x,y,z;                //input variables
  
LOCAL total,sum_xy,prod_xy,sq_x;

  
z1:=0;  //zero WHILE loop counter 

  //This WHILE loop will repeat the tap procedures, until the user presses one of the active tabs.
  //After which, the program runs the tab procedures, and the program ends by using the RETURN command.
  //This loop will repeat if the tap was not on an active user tab.  The loop counter is always equal to zero.
  //This causes the loop to continuously loop, until the RETURN command is executed.
  
WHILE z1==DO

    
RECT;  //Clears G0 screen, makes G0 current screen.

    
DRAWMENU("total""x+y""x*y""x^2""""exit"); //Draws the tabs on the current screen (G0).
                                                        //These tabs are just pictures 
                                                        //and have no special features.

    
WAIT(0.25);  //Some programs require a wait statement to display the G0 screen.
  
    // This REPEAT-UNTIL loop will fetch the screen tap coordinates.  Note that the user can tap
    // one of the user tabs, or an area outside of the active user tab, such as in the middle of the screen.  
    
REPEAT 
      m 
:= MOUSE;         //MOUSE dispays the current screen (G0) and pauses the program 
                          //and waits for a tap on the screen. Key presses are ignored.
                          //When the screen is tapped, returns list of tap coordinates and other info
      
m1 := m(1);         //Stores first element of the list of tap coordinates {x, y, original x, original y, type}
                          //An example of m1 is {#77:-16d,#229:-16d,#77:-16d,#229:-16d,#1:16d}
                          //For a tap, x and y is the same as original x and original y. Type = 1
    
UNTIL SIZE(m1) > 0;   //exits the loop when the first packet of mouse coordinates are recieved.
                          //A split second later, MOUSE will send a second packet of info.
 
    
mx := m1(1);          //Stores x tap coordinate. An example of mx is #77:-16d, where 77 is the x coordinate
    
my := m1(2);          //Stores y tap coordinate. An example of my is #229:-16d, where 229 is the y coordinate

    // These nested IF statements check to see if the tap was within the user tab
    
IF my ≥ 220 AND my ≤ 239 THEN          //Was the screen tap within the row of user tabs?

      
IF mx ≥ 0 AND mx ≤ 51 THEN           //Was tab 1 "total" pressed?
        
INPUT({{x,[0],{24,18,2}},
               {
y,[0],{24,18,3}},
               {
z,[0],{24,18,4}}},
              
"User Tabs Input Example",
              {
"x = ",
               
"y = ",
               
"z = "});
        
total:=x+y+z;
        RETURN(
total);                            
      
END;
    
      IF 
mx ≥ 53 AND mx ≤ 104 THEN         //tab 2 "x+y"
        
INPUT({{x,[0],{24,18,2}},
               {
y,[0],{24,18,3}},
               {
z,[0],{24,18,4}}},
              
"User Tabs Input Example",
              {
"x = ",
               
"y = ",
               
"z = "});       
        
sum_xy:=x+y;
        RETURN(
sum_xy);
      
END;

      IF 
mx ≥ 106 AND mx ≤ 157 THEN        //tab 3 "x*y"
        
INPUT({{x,[0],{24,18,2}},
               {
y,[0],{24,18,3}},
               {
z,[0],{24,18,4}}},
              
"User Tabs Input Example",
              {
"x = ",
               
"y = ",
               
"z = "});
        
prod_xy:=x*y;
        RETURN(
"x*y = "+prod_xy);           
      
END;

      IF 
mx ≥ 159 AND mx ≤ 210 THEN        //tab 4 "x^2"
        
INPUT(x);                          
        
sq_x:=x^2;
        PRINT();                           
        PRINT(
"x^2 = "+sq_x);              //writes to the print terminal
        
RETURN(sq_x);                      //The RETURN serves two functions, It ends the program and allows
      
END;                                 //print terminal to be displayed. It also returns the answer 
                                           //to the home screen.  The user must press the Esc key 
                                           //to switch back to the Home screen.

      
IF mx ≥ 212 AND mx ≤ 263 THEN        //tab 5
        //no action
      
END;

      IF 
mx ≥ 265 AND mx ≤ 319 THEN        //tab 6 "exit"
        
KILL;                              //The KILL command works better than the RETURN command to exit the program
      
END;

    
END// nested IF statements

  
END;  // WHILE loop

END//main program 
Find all posts by this user
Quote this message in a reply
04-15-2019, 07:48 PM (This post was last modified: 05-06-2019 12:10 AM by Gene222.)
Post: #4
RE: User tabs
I apologize for putting forum readers through my ramblings on user tab. I was frustrated with trying to learn how to use user tabs. Examples of user tabs on the web were too complex and did not really explain how user tabs worked. One example did not even work.

A much better example of user tabs can be found in the Cash Flow (IRR, MIRR, NPV) program by salvomic in the HP Prime programs section. The program below was based on salvomic's code.

PHP Code:
EXPORT UserTabs9c()
BEGIN
// Initialize local variables used within this procedure
LOCAL mx,my,mTXT,EXITPGM;
LOCAL eTYP,kp,m,m1;
LOCAL x,y,z,product_xy;

EXITPGM:=0;
 
// This WHILE loop will continuously loop until one of the menu taps is pressed or the
// program is ended.  This loop is necessary to disregard screen taps that are NOT 
// on one of the menu tabs.
WHILE EXITPGM==DO
   
// Draw the menu screen
   
RECT_P();  // Clear the G0 screen
   
TEXTOUT_P("Menu Tabs Example",10,20);
   
TEXTOUT_P("This menu screen will continously be displayed",10,50);
   
TEXTOUT_P("on the G0 screen, until (1) the Esc key is",10,65);
   
TEXTOUT_P("pressed, (2) the Quit tab is pressed, (3) the On",10,80);
   
TEXTOUT_P("key is pressed, (4) the tab code executes the",10,95);
   
TEXTOUT_P("RETURN command, or (5) the tab code assigns",10,110);
   
TEXTOUT_P("EXITPGM = 1 to exit the WHILE loop.",10,125);
   
TEXTOUT_P("This menu program was based on the menu",10,155);
   
TEXTOUT_P("code from the Cash Flow (IRR, MIRR, NPV)",10,170);
   
TEXTOUT_P("program by salvomic.",10,185);
   
// Draw the menu tabs on the G0 screen
   
DRAWMENU("x+y","x*y","","","","Quit");
   
// Flush the mouse buffer
   
WHILE MOUSE(1)≥0 DO END;
   
// Loop until we have a keyboard or mouse event
   
REPEAT
      eTYP
:="";
      
kP:=GETKEY;
      IF 
kP<>(-1THEN
         eTYP
:="K";
      ELSE
         
m:=MOUSE;
         
m1:=m(1);
         IF 
SIZE(m1)>0 THEN
            eTYP
:="M";
         
END;
      
END;
   
UNTIL eTYP<>"";
   CASE
      
// If the event type was a keyboard action then process it
      
IF eTYP=="K" THEN
         
// If the ESC key was pressed set the program to end
         
IF kP==4 THEN
            EXITPGM
:=1;  
         ELSE
            
// ESC was not pressed. Do what you want with the keypress.  This program skips to the MOUSE
            // code.        
         
END;        
      
END;
      
// If the event type was mouse action then process it
      
IF eTYP=="M" THEN
         
// Convert mouse coordinates to decimal
         
mx:=B→R(m1(1));  
         
my:=B→R(m1(2));
         
// Determine if mouse coordinates are inside of a valid menu item otherwise return a zero
         
IF my≥220 AND my≤239 THEN
            
CASE
               IF 
mx≥0 AND mx≤51 THEN    // tab 1 "x+y" Returns sum of x and y to the Home screen.
                  
INPUT({x,y});
                  RETURN(
"x+y = "+(x+y));
               
END;
               IF 
mx≥53 AND mx≤104 THEN  // tab 2 "x*y" Returns the product of x and y to the print terminal.
                  
INPUT({x,y});
                  
product_xy:=x*y;
                  PRINT();
                  PRINT(
"x = "+x);
                  PRINT(
"y = "+y);
                  PRINT(
"x * y = "+product_xy);
                  
EXITPGM:=1;  // used to exit the WHILE loop and ends the program.
                               // The answer is not returned to the home screen.
               
END;
               IF 
mx≥106 AND mx≤157 THEN  // tab 3
                  //mSEL := 3;
               
END;
               IF 
mx≥159 AND mx≤210 THEN  // tab 4
                  //mSEL := 4;
               
END;
               IF 
mx≥212 AND mx≤263 THEN  // tab 5 is not used
                  //no action
               
END;
               IF 
mx≥265 AND mx≤319 THEN  // tab 6 "Quit" tab
                  
EXITPGM:=1;
               
END;
               
// If none of the active tabs was pressed, the program will continue back
               // to the WHILE loop.
            
END//CASE
         
END//IF my≥220 AND my≤23
      
END//IF eTYP=="M"
   
END//CASE
END//WHILE EXITPGM==0
END//main program 

(added 4/21/19) The WAIT(-1) command is much better than all of the above MOUSE command programs. If the screen is tapped, the WAIT(-1) will return the list {type, x coordinate, y coordinate}. For a screen tap, type = 3. For an example of the WAIT(-1) command see the Blackjack program by Geoff.

(added 5/2/19) The program below is a simplified example of the WAIT(-1) command based on the Blackjack program by Geoff. It uses the G0 screen. The program below also fixes the problem I was having in all of the above programs, where I could not cleanly exit the loops to either repeat the program, repeat the input screen with the old values shown, or exit the program and return the answer to the home screen. This was done by using the BREAK command with nested loops. As this thread has no interests, I am posting this in case someone reads this old post while trying to learn about user tabs. (added 5/3/19) When using WAIT(-1), key handling procedures also need to be included in the program. (5/5/19) The above programs will drain the calculator batteries, if left unattended. The program below was rewritten to exit the program if there are no screen taps or key presses after 3 minutes.

[Image: 9znez9.png]

PHP Code:
EXPORT UserTabs9e2()
BEGIN
LOCAL a
,b,c,sum,answer;
LOCAL event,loop_1,loop_2,loop_3,loop_3_count;
//initialize continuous loop counter variables
loop_1:=1;
loop_2:=1;
loop_3:=1;
WHILE 
loop_1==DO
  
a:=0;  //clear variables
  
b:=0;
  
c:=0;
  WHILE 
loop_2==DO
    
INPUT({a,b,c});
    
sum:=a+b+c;
    
answer:=sum;
    
loop_3_count:=0;   //initialize loop 3 cycle counter
    
WHILE loop_3==DO //loop 3
      
loop_3_count:=loop_3_count+1;
      
//if there are no tap or key events after 3 WAIT(-1) cycles (3 minutes), exit program
      
IF loop_3_count==4 THEN
        
//exit program
        
BREAK(3);  //exit loops 3, 2, and 1
      
END;
      
//draw G0 screen
      
RECT();
      
TEXTOUT_P("User Tab Demonstration",10,15);
      
TEXTOUT_P("a = "+a,10,45);
      
TEXTOUT_P("b = "+b,10,60);
      
TEXTOUT_P("c = "+c,10,75);
      
TEXTOUT_P("sum = "+sum,10,105);
      
TEXTOUT_P("Loop 3 WAIT(-1) counter = "+loop_3_count,10,135);
      
DRAWMENU("""""""exit""clear""↩");
      
//pause up to 60 seconds to get a screen tap or key press and store the tap or key data into "event"
      
event:=WAIT(-1);  
      
//key press handling procedues
      
IF TYPE(event)==0 THEN     //Is the variable "event" a real number?
        
IF event==4 THEN         //Was the "Esc" key pressed?
          //exit the program by going to end of loop 1
          
BREAK(3);              //exit loop 3, loop 2, loop 1
        
END;
      
END;
      
//mouse tap handling procedures
      
IF TYPE(event)==6 THEN     //Is the variable "event" a list.
        
IF event(1)==3 THEN      //Is the MOUSE event type a mouse click (i.e. screen tap)?
          
IF event(3) > 219 THEN //Was the y coordinate tap within the row of user tabs?
            
IF event(2≥ 0 AND event(2≤ 51 THEN     //tab 1  Is the x coordinate within tab 1?
              //no action                            
            
END;
            IF 
event(2≥ 53 AND event(2≤ 104 THEN   //tab 2
              //no action
            
END;
            IF 
event(2≥ 106 AND event(2≤ 157 THEN  //tab 3
              //no action          
            
END;
            IF 
event(2≥ 159 AND event(2≤ 210 THEN  //tab 4 "exit"
              //go to end of loop 1
              
BREAK(3);          //exit loops 3, 2, and 1
            
END;
            IF 
event(2≥ 212 AND event(2≤ 263 THEN  //tab 5 "clear"
              //go to end of loop 2, and then goes to the beginning of loop 1
              
BREAK(2);          //exit loops 3, and 2
            
END;
            IF 
event(2≥ 265 AND event(2≤ 319 THEN  //tab 6 "↩"
              //go to end of loop 3, and then goes to the beginning of loop 2
              
BREAK(1);          //exit loop 3
            
END;
          
END;
        
END;
      
END//if TYPE(event)==6
    
END//loop 3
  
END//loop 2
END//loop 1
RETURN answer;  //returns the answer to the home screen
END//main program 
Find all posts by this user
Quote this message in a reply
Post Reply 




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