Post Reply 
[REPORT] problem with choose CMD
12-03-2016, 04:27 PM (This post was last modified: 12-07-2016 02:23 PM by compsystems.)
Post: #1
[REPORT] problem with choose CMD
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
Find all posts by this user
Quote this message in a reply
12-03-2016, 04:40 PM
Post: #2
RE: problem with choose CMD
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).

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
12-03-2016, 05:05 PM
Post: #3
RE: problem with choose CMD
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"  }); // =( 
Find all posts by this user
Quote this message in a reply
12-03-2016, 05:33 PM (This post was last modified: 12-03-2016 05:40 PM by StephenG1CMZ.)
Post: #4
RE: problem with choose CMD
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.

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
12-03-2016, 06:12 PM
Post: #5
RE: problem with choose CMD
(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;

My website: ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
12-03-2016, 06:27 PM
Post: #6
RE: problem with choose CMD
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.

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
12-04-2016, 04:21 AM
Post: #7
RE: problem with choose CMD
(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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
12-05-2016, 03:28 PM
Post: #8
RE: problem with choose CMD
(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...

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: 1 Guest(s)