Post Reply 
Improved change of integer base
03-02-2014, 04:27 PM (This post was last modified: 03-02-2014 04:28 PM by Angus.)
Post: #11
RE: Improved change of integer base
hello,

I apologize for double posting, but some questions came up while I work with the hp prime.

Code:

EXPORT SoftMenu(buttons)
BEGIN
  DRAWMENU(buttons);
  LOCAL inp:=WAIT(-1);                    
  IF TYPE(inp)≠6 THEN RETURN inp; END;    
  //IF inp(1)≠#0d THEN RETURN""; END;  
  IF inp(1)≠#0d AND
     inp(1)≠#3d AND
     inp(1)≠#7d THEN RETURN ""; END;      
  IF inp(3)<#220d THEN RETURN ""; END;   
  LOCAL btn:=1+IP(inp(2)*6/320);            
  RETURN btn;
END;


KEY KS_Minus()
BEGIN
  LOCAL menu, ret; 
  menu:={"#dec","#hex","#bin","R->B","B->R","#"};
  ret:=SoftMenu(menu);

  IF Entry==2 THEN 
  //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  //RPN
  //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  //DUPN; //how would you use Stack commands in a program?
    //IF TYPE(1)==0 THEN //needs integer conversion  
//????????IF there is an integer constabt #1234 on the stack / command line the user key seems to be ignored?
//DROP //???????would the comparison drop it?
    CASE
      IF ret==1 THEN RETURN " 32 3 R→B(3)"; END;
      IF ret==2 THEN RETURN " 32 4 R→B(3)"; END;
      IF ret==3 THEN RETURN " 32 1 R→B(3)"; END;
      IF ret==4 THEN RETURN "R→B()"; END;
      IF ret==5 THEN RETURN "B→R()"; END;
      IF ret==6 THEN RETURN "#"; END;
      DEFAULT RETURN "";
//??????'autoexecute' of the command? doing an auto <enter>
    END;
    //END;
  ELSE 
  //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  //TEXTBOOK
  //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
//???????can you use the command line as argument aswell?
     CASE
      IF ret==1 THEN RETURN "R→B("+Ans+",32,3)"; END;
      IF ret==2 THEN RETURN "R→B("+Ans+",32,4)"; END;
      IF ret==3 THEN RETURN "R→B("+Ans+",32,1)"; END;
      IF ret==4 THEN RETURN "R→B("+Ans+")"; END;
      IF ret==5 THEN RETURN "B→R("+Ans+")"; END;
      IF ret==6 THEN RETURN "#"; END;
      DEFAULT RETURN "";
    END;
  END;
END;

Converting to integer-type works so far. My intention is to switch between bases if there is already an integer constant available as argument (that is SETBASE). But it seems that Shift+Minus starts the base window and the user key is ignored then.
Is there a way to prevent that? using F6 to launch the window in my example would be my choice. Can you confirm, that base can't be used as user-key for integer type values?

Using rpn entry: I tried to do a if TYPE()==0 to check for real number. That would require a DUPN of the original argument. How can I invoke stack commands?
And is there a way to execute the command line that is returned?

Using textbook entry: is it really impossible to use input from the command line directly?


If someone likes to comment on the code fragment please feel free to post. Feedback is important for learning.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Improved change of integer base - Angus - 02-24-2014, 12:12 PM
RE: Improved change of integer base - Angus - 03-02-2014 04:27 PM



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