Post Reply 
[QUESTION] data types on "input" cmd
12-07-2016, 02:43 PM (This post was last modified: 12-07-2016 08:11 PM by compsystems.)
Post: #1
[QUESTION] data types on "input" cmd
Hello HP-PRIME programmers and users

According to the help in data types of "INPUT" cmd, if the value is -1, it means "allow all types" (REAL, COMPLEX, ..., etc), I'm misunderstanding?.

Executing the dialog box, an output message is generated "Error: Invalid input" Why?

Test code
PHP Code:
export input0()
begin
    local a
bc;
    
local resetVAL_aresetVAL_bresetVAL_c;
    
local initVAL_ainitVAL_binitVAL_c;

    
//initVAL_a:=1; initVAL_b:=2; initVAL_c:=3; // real
    //initVAL_a:=#FFFh; initVAL_b:=#FFh; initVAL_c:=#Fh; // integer
    //initVAL_a:="abc"; initVAL_b:="123"; initVAL_c:="X"; // string
    //initVAL_a:=i; initVAL_b:=(3,4); initVAL_c:=3+4*i; // complex
    
initVAL_a:=[1]; initVAL_b:=[2]; initVAL_c:=[3]; // matrix  
    //initVAL_a:={1}; initVAL_b:={2}; initVAL_c:={3}; // list  
    //initVAL_a:=cas( "f(x):=x+20" ); initVAL_b:=cas( "f(x):=x+30" ); initVAL_c:='A+B'; // function
    //initVAL_a:=1_m; initVAL_b:=2_cm; initVAL_c:=3_inch; // real

    
resetVAL_a:=0resetVAL_b:=0resetVAL_c:=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 ObjectType := ObjectType_List;
    
local title;

    case
        if 
ObjectType == 0 then title:="Real" end;
        if 
ObjectType == 1 then title:="Integer" end;
        if 
ObjectType == 2 then title:="String" end;  
        if 
ObjectType == 3 then title:="Complex" end;  
        if 
ObjectType == 4 then title:="Matrix" end;
        if 
ObjectType == 6 then title:="List" end;
        if 
ObjectType == 8 then title:="Function" end;  
        if 
ObjectType == 9 then title:="Unit" end;  
        if 
ObjectType == 14 then title:="CAS" end;
     default
        
title:="?"
     
end;

    
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 keyPressedOnMenu := 0;
    
keyPressedOnMenu := input 
    
(  
        { 
         {
a, [ObjectType] }, 
         {
b, [ObjectType] },
         {
c, [ObjectType] }

        }, 
        
title,
        { 
"label_a""label_b","label_c" }, 
        { 
"help_a""help_b""help_c" },           
        { 
resetVAL_aresetVAL_bresetVAL_c }, 
        { 
initVAL_ainitVAL_binitVAL_c 
    );
    if 
keyPressedOnMenu == ok then
        
return ({abc});  
        
//return ([expr(a), expr(b), expr(c)]); // for -1 
    
else
        return 
"Done";
    
end;
end
Find all posts by this user
Quote this message in a reply
12-07-2016, 05:02 PM (This post was last modified: 12-07-2016 05:03 PM by Tim Wessman.)
Post: #2
RE: [QUESTION] data types on "input" cmd
(12-07-2016 02:43 PM)compsystems Wrote:  return ([a, b, c]);


You are returning a vector/matrix of strings. That is not a valid object type. Try typing ["1"] and you will see the same error.

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
12-07-2016, 05:42 PM (This post was last modified: 12-07-2016 08:15 PM by compsystems.)
Post: #3
RE: [QUESTION] data types on "input" cmd
Thanks TIM, the output is converted into a string
Thus requires conversion to expression

return ([a, b, c]); ->
return ([expr(a), expr(b), expr(c)]);
or
return ({a, b, c});

A help for data types
[Image: objectTypes_hp_prime_image00.png]

I think initialization variables should also be detected with the data type, in order to load correctly.

The following code does not generate error, Type defined LIST, type loaded Matrix, should generate a"Error: Invalid type , a list is expected"


PHP Code:
export input0()
begin
    local a
bc;
    
local resetVAL_aresetVAL_bresetVAL_c;
    
local initVAL_ainitVAL_binitVAL_c;

    
//initVAL_a:=1; initVAL_b:=2; initVAL_c:=3; // real 0 
    //initVAL_a:=#FFFh; initVAL_b:=#FFh; initVAL_c:=#Fh; // integer 1 
    //initVAL_a:="abc"; initVAL_b:="123"; initVAL_c:="X"; // string 2
    //initVAL_a:=i; initVAL_b:=(3,4); initVAL_c:=3+4*i; // complex 3
    
initVAL_a:=[1]; initVAL_b:=[2]; initVAL_c:=[3]; // matrix 4
    //initVAL_a:={1}; initVAL_b:={2}; initVAL_c:={3}; // list 6 
    //initVAL_a:=cas( "f(x):=x+20" ); initVAL_b:=cas( "f(x):=x+30" ); initVAL_c:='A+B'; // function 8
    //initVAL_a:=1_m; initVAL_b:=2_cm; initVAL_c:=3_inch; // unit 9

    
resetVAL_a:=0resetVAL_b:=0resetVAL_c:=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 ObjectType := ObjectType_List;
    
local title;

    case
        if 
ObjectType == 0 then title:="Real" end;
        if 
ObjectType == 1 then title:="Integer" end;
        if 
ObjectType == 2 then title:="String" end;  
        if 
ObjectType == 3 then title:="Complex" end;  
        if 
ObjectType == 4 then title:="Matrix" end;
        if 
ObjectType == 6 then title:="List" end;
        if 
ObjectType == 8 then title:="Function" end;  
        if 
ObjectType == 9 then title:="Unit" end;  
        if 
ObjectType == 14 then title:="CAS" end;
     default
        
title:="?"
     
end;

    
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 keyPressedOnMenu := 0;
    
keyPressedOnMenu := input 
    
(  
        { 
         {
a, [ObjectType] }, 
         {
b, [ObjectType] },
         {
c, [ObjectType] }

        }, 
        
title,
        { 
"label_a""label_b","label_c" }, 
        { 
"help_a""help_b""help_c" },           
        { 
resetVAL_aresetVAL_bresetVAL_c }, 
        { 
initVAL_ainitVAL_binitVAL_c 
    );
    if 
keyPressedOnMenu == ok then
        
return ({abc});  
        
//return ([expr(a), expr(b), expr(c)]); // for -1 
    
else
        return 
"Done";
    
end;
end
Find all posts by this user
Quote this message in a reply
Post Reply 




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