HP Forums
[REPORT] problem with choose CMD - 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: [REPORT] problem with choose CMD (/thread-7359.html)



[REPORT] problem with choose CMD - compsystems - 12-03-2016 04:27 PM

Hello

The logic of the following code fails, because choose must return 1 when [OK/ENTER] is pressed


PHP Code:
export INPUTtest0()
    
begin
      local coef1_a
coef2_bcoef3_ccoef4_d
      
coef1_a:=9coef2_b:=8coef3_c:=7coef4_d:=6;

      
local reset_coef1_areset_coef2_breset_coef3_creset_coef4_d
      
reset_coef1_a:=3reset_coef2_b:=2reset_coef3_c:=1reset_coef4_d:=0;

      
local init_coef1_ainit_coef2_binit_coef3_cinit_coef4_d
      
init_coef1_a:=coef1_ainit_coef2_b:=0init_coef3_c:=0init_coef4_d:=0;

      
local ObjectType_AllAllowed := -1;
      
local ObjectType_Real := 0;
      
local ObjectType_Integer := 1;
      
local ObjectType_String := 2;    
      
local ObjectType_Complex := 3;    
      
local ObjectType_Matrix := 4;
      
local ObjectType_List := 6;
      
local ObjectType_Function := 8;    
      
local ObjectType_Unit := 9;    
      
local ObjectType_CAS := 14;

      
local ok:=1;
      
local cancel:=0;
      
local keyPress:=0;
      
local currentPos:=2;
      print(); 
freeze;

      
keyPress:= input( { {coef1_a, [ObjectType_Real]}, {coef2_b, [ObjectType_Real]}, {coef3_c, [ObjectType_Real]}, {coef4_d, [ObjectType_Real] } }, "a x² + b x + c = 0 ∨ ax²+bx=d",  {"a:""b:""c:""d:"}, {"Enter coeff a""Enter coeff b""Enter coeff c""Enter coeff d"} , {reset_coef1_a,0,0,0}, {init_coef1_a,2,3,4} );

      print(
"Key press for INPUT CMD: " ifte(keyPress == ok,"[OK/ENTER]","[ESC]") );
      if 
keyPress == ok then
        coef3_c 
:= coef3_c-coef4_d// => ax²+bx+c=0
        
print( "a=" coef1_a );
        print( 
"b=" coef2_b );
        print( 
"c=" coef3_c ); wait;

        
//keyPress:=0;
        
keyPress:= choose(currentPos,"test choose",{"a","b","c"});

        print(
"Key press for CHOOSE CMD: " keyPress ); // 0 for [CANCEL], 1 for [OK/ENTER]
        
print("Key press: " ifte(keyPress == ok,"[OK/ENTER]","[ESC]") );
        print( 
"selected position = " currentPos ); wait;
        if 
keyPress == ok then
          
print("Key press for CHOOSE CMD: " keyPress ); wait;
        
end;
      
end;

      return 
"done";
    
end



RE: problem with choose CMD - eried - 12-03-2016 04:40 PM

Syntax:
CHOOSE(var, “title”, “item1”, “item2”,[…"item14"]) or
CHOOSE(var,"title",{"item1"..."itemN"})

Displays a choose box with the given "title" and containing items with the strings "item1", etc.

If the user chooses an object, var will be updated to contain the number of the selected object (an integer, 1, 2, 3, …); otherwise, stores zero in var if the user exits without choosing.

Returns true (non zero) if the user selects an object, otherwise returns false (0).


RE: problem with choose CMD - compsystems - 12-03-2016 05:05 PM

According to the help this CHOOSE cmd is correct, but it has not utility because the variable of the position returns the place of the selection, the output must be 1/0 as does INPUT CMD

Another improvement that must be made is that, it should be labeled up "Z"

PHP Code:
choose(currentPos,"test choose",{ "1""2""3""4""5""6""7""8""9""A""B""C""D""E""F""G""H""I""J""K""L""M""N""O"  }); // OK

choose(currentPos,"test choose",{ "1""2""3""4""5""6""7""8""9""A""B""C""D""E""F""G""H""I""J""K""L""M""N""O""P""Q""R""S""T""U""V""W""X""Y""Z"  }); // =( 



RE: problem with choose CMD - StephenG1CMZ - 12-03-2016 05:33 PM

Compsystems, a few words of explanation of what it is that you are trying to achieve would help greatly.

Since you have several inputs but want a 0 or 1 rather than a position...
Do you want to enter (a,b,c,d)
And see {0,1,0,1}
for example...depending on which values the user has entered?

Or something else?

The fact that your example says it is OK from A to O suggests the difficulty may be related to keyboard mapping..Up to "O" the alphabet is unambiguous and items can be chosen by tapping the relevant key instead of scrolling. . After "O" that is no longer possible as the alphabet begins to overlap the numbers on the HP Prime keypad.


RE: problem with choose CMD - eried - 12-03-2016 06:12 PM

(12-03-2016 05:33 PM)StephenG1CMZ Wrote:  Compsystems, a few words of explanation of what it is that you are trying to achieve would help greatly.

Since you have several inputs but want a 0 or 1 rather than a position...
Do you want to enter (a,b,c,d)
And see {0,1,0,1}
for example...depending on which values the user has entered?

Or something else?

The fact that your example says it is OK from A to O suggests the difficulty may be related to keyboard mapping..Up to "O" the alphabet is unambiguous and items can be chosen by tapping the relevant key instead of scrolling. . After "O" that is no longer possible as the alphabet begins to overlap the numbers on the HP Prime keypad.

I think he wants 1 and 0 for OK and CANCEL instead of VALUE and 0 for OK and CANCEL.

CHOOSE is probably using the same variable for both, I don't see the benefit of adding an extra step besides nitpicking something.

Just use:
Code:
IF( choose(var,"title",{something,...}) ) THEN
// use var here, user did not press CANCEL
ELSE
// user pressed CANCEL
END;



RE: problem with choose CMD - StephenG1CMZ - 12-03-2016 06:27 PM

If the only problem is the test

If keypress==OK

Failing because keypress is N rather than 1
On the HP Prime you can just use

If keypress then

Any non-zero value will pass the test.

A very convenient syntax.


RE: problem with choose CMD - Han - 12-04-2016 04:21 AM

(12-03-2016 05:33 PM)StephenG1CMZ Wrote:  The fact that your example says it is OK from A to O suggests the difficulty may be related to keyboard mapping..Up to "O" the alphabet is unambiguous and items can be chosen by tapping the relevant key instead of scrolling. . After "O" that is no longer possible as the alphabet begins to overlap the numbers on the HP Prime keypad.

Use the Alpha modifier key for keys that have both numbers and letters assigned to them.


RE: problem with choose CMD - Tim Wessman - 12-05-2016 03:28 PM

(12-04-2016 04:21 AM)Han Wrote:  
(12-03-2016 05:33 PM)StephenG1CMZ Wrote:  The fact that your example says it is OK from A to O suggests the difficulty may be related to keyboard mapping..Up to "O" the alphabet is unambiguous and items can be chosen by tapping the relevant key instead of scrolling. . After "O" that is no longer possible as the alphabet begins to overlap the numbers on the HP Prime keypad.

Use the Alpha modifier key for keys that have both numbers and letters assigned to them.

Well, but then the alpha search doesn't work...