HP Forums
Entering the 'Edit Integer' window - 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: Entering the 'Edit Integer' window (/thread-21014.html)

Pages: 1 2


Entering the 'Edit Integer' window - matalog - 12-19-2023 08:12 PM

A little thing that niggles me a lot is when trying to enter the 'Edit Integer' window to convert hex to dec etc, which I often do, I press Shift then press '-'. Most of the time upon first press the calculator will output a # to the home screen.

What causes this, and how can I stop it? Is it possible for me to set up my own shortcut to call the 'Edit Integer' window?


RE: Entering the 'Edit Integer' window - KeithB - 12-19-2023 08:52 PM

Isn't that just letting you enter a hex value?


RE: Entering the 'Edit Integer' window - matalog - 12-19-2023 08:57 PM

(12-19-2023 08:52 PM)KeithB Wrote:  Isn't that just letting you enter a hex value?

Well, ALPHA + '3' is designed to Enter a '#'. I don't know why SHIFT + '-' is doing it.

Is it a bug or does it have a use?


RE: Entering the 'Edit Integer' window - KeithB - 12-19-2023 10:21 PM

It signals that you are about to do integer arithmetic:
"You indicate that you are about to engage in integer arithmetic by preceding the number with the pound symbol (#,"

The intent of the integer screen is to let you enter a number in any base.


RE: Entering the 'Edit Integer' window - matalog - 12-19-2023 11:02 PM

(12-19-2023 10:21 PM)KeithB Wrote:  It signals that you are about to do integer arithmetic:
"You indicate that you are about to engage in integer arithmetic by preceding the number with the pound symbol (#,"

The intent of the integer screen is to let you enter a number in any base.

Sorry, I don't seem to be understanding you.

I know what the pound symbol is for, but it is supposed to be called by the Alpha key plus the '3' key. Not by the Shift key plus the '-' key.


RE: Entering the 'Edit Integer' window - Dougggg - 12-20-2023 12:26 AM

You can use either one it is the same character, it may have been oversight bu eitherbone will work

Actually may be a bug, in home the base I get a #, in cas it pulls up a edit integer screen, probably in home should pull up the edit integer as well, I think it use to


RE: Entering the 'Edit Integer' window - BruceH - 12-20-2023 12:56 AM

(12-20-2023 12:26 AM)Dougggg Wrote:  Actually may be a bug, in home the base I get a #, in cas it pulls up a edit integer screen, probably in home should pull up the edit integer as well, I think it use to

In Home, if item 1 on the history stack is an integer, then SHIFT+Base brings up the Edit Integer screen. Otherwise it puts # into the input line.

This behaviour is too deliberate to be a mistake so make of it what you will. I suspect they thought of a better way for SHIFT+Base to work only after the keyboard layout was finalised and it was too late to change the character that ALPHA-3 produced.


RE: Entering the 'Edit Integer' window - matalog - 12-21-2023 09:20 AM

So is there a way to definitely get into the Edit Integer window with one or 2 key presses?

Is there any way to call the window from a program? In which case, I could write a program to get me there in one keypress.


RE: Entering the 'Edit Integer' window - KeithB - 12-21-2023 02:20 PM

I don't see a "BASE" or "EDITBASE" command in the toolbox catalog.


RE: Entering the 'Edit Integer' window - Tschumi81 - 12-26-2023 07:24 PM

(12-19-2023 11:02 PM)matalog Wrote:  
(12-19-2023 10:21 PM)KeithB Wrote:  It signals that you are about to do integer arithmetic:
"You indicate that you are about to engage in integer arithmetic by preceding the number with the pound symbol (#,"

The intent of the integer screen is to let you enter a number in any base.

Sorry, I don't seem to be understanding you.

I know what the pound symbol is for, but it is supposed to be called by the Alpha key plus the '3' key. Not by the Shift key plus the '-' key.

Hi Matalog

First entering in hex, octal, decimal or binary like: ALPHA-3, Value, Format; '#11001b', Enter.
When in the first stack, '2nd', 'Base' and it opens the integer arithmetic with the Input from stack.

Regards, Tschumi


RE: Entering the 'Edit Integer' window - komame - 12-26-2023 09:38 PM

In general, to enter the "Edit Integer" window with the first press of Shift [-], there are two approaches. The first approach involves having an integer value on the history stack (marked with a "#" sign at the beginning) as someone already mentioned in this thread. As for the second approach, the only condition is to be in edit mode (blinking cursor). There doesn't need to be any value on the stack or even in the editing field where the cursor is; you just need to enter the edit mode of anything. For instance, you can go to HOME and press the space, multiplication, or any other key that outputs any character on the screen (then the cursor will appear - edit mode), then press Shift [-] and the "Edit Integer" window will open immediately. Another good example is the PPL editor, which is always in edit mode and pressing Shift [-] always immediately opens "Edit Integer".
If you're not in edit mode, the first press produces "#" and simultaneously switches to edit mode, so the second press opens the "Edit Integer" window and the "#" character here has no impact on the fact of opening this window.
I am convinced that the appearance of the "#" sign after pressing Shift [-] is not only problematic, but it is definitively a bug. This is because if there’s no value on the stack and the first press of Shift [-] causes "#" to appear, and the second press opens the "Edit Integer" window, then after finishing editing the value by clicking "OK" (or pressing Enter), the "#" sign is automatically added, which results in a double "#" sign, such as ##64, in the command line in HOME, which is an incorrect value.
I see no justification for such behavior.

(12-20-2023 12:26 AM)Dougggg Wrote:  Actually may be a bug, in home the base I get a #, in cas it pulls up a edit integer screen, probably in home should pull up the edit integer as well, I think it use to
Nope, in CAS it behaves exactly the same way as in HOME.
On the other hand, using this in CAS probably doesn't make sense, because the result of the editing from this window will be interpreted in CAS as a character string, not as a number.


RE: Entering the 'Edit Integer' window - Tschumi81 - 12-27-2023 06:54 AM

(12-21-2023 09:20 AM)matalog Wrote:  So is there a way to definitely get into the Edit Integer window with one or 2 key presses?

Is there any way to call the window from a program? In which case, I could write a program to get me there in one keypress.

I don't know, but 'GETBASE()' can be the solution with a Prog..
When SETBASE is predefined to decimal (Settings -> Integer)you also can go the way with '#25', '2nd', 'Base'.


Regards


RE: Entering the 'Edit Integer' window - komame - 01-04-2024 06:16 PM

(12-21-2023 09:20 AM)matalog Wrote:  So is there a way to definitely get into the Edit Integer window with one or 2 key presses?

Is there any way to call the window from a program? In which case, I could write a program to get me there in one keypress.

Hi Matalog,

If you use the "Customizing key presses" described in the manual (third edition) on page 615, you can enable persistent user mode (by pressing the "User" combination twice (Shift+Help, Shift+Help)) and then, by applying the appropriate program, you can simulate the "Edit Integer" window.
I am attaching a very simple example that demonstrates this capability. It also works in other programs, even in the PPL editor.
[attachment=13109]

But it's just a proof of concept; it converts only from DEC to HEX and only small numbers. Only the keys from 0 to 9, backspace and Enter work; there's no error handling, no optimization, etc. However, you can adapt it to your needs and then you'll probably achieve what you're looking for.

The header "KEY KS_Minus()" means that the program is assigned to the "Base" function, replacing the original "Edit Integer" mechanism as long as you have the user mode enabled.

Best wishes,
Piotr


RE: Entering the 'Edit Integer' window - matalog - 01-07-2024 11:23 PM

Yes, good idea, it's great for quick conversion of dec to hex.

Thanks.


RE: Entering the 'Edit Integer' window - matalog - 01-08-2024 12:33 AM

Here is the program adapted to convert Hex to Dec or Dec to Hex, you can switch with the 'Apps' button.

Code:
KEY KS_Minus()
BEGIN
  local hc="0123456789ABCDEF";
  local w, s, d, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,-1,15});
  keys[0]:=20;   //
  keys[19]:=99;  //backspace
  keys[30]:=100; //enter
  local s,h,i,he,curkey;
 he:=0;
  RECT_P(80,80,240,146,0,16777215);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,16777215);
  TEXTOUT_P("ENTER => OK",88,130,1);
  REPEAT
 IF he=0 THEN
    w:=IFTE(value=0,88,TEXTOUT_P(STRING(value,1),88,86,2,0,144,16777215));
    s:=CONVERT(value,"base",16);
    d:=GET(SIZE(s),1);
    h:="";
    FOR i FROM 1 TO d DO

      h:=h+CHAR(hc[s[i]+1]);

    END;

    RECT_P(w,81,239,97);
    RECT_P(w,86,w+9,97,0);
    w:=TEXTOUT_P("HEX: "+h,88,100,2,0,144,16777215);
    RECT_P(w,100,239,111);
    key:=keys[WAIT(0)];
    IF key=100 THEN
      RETURN "#"+h+"h";
    END;
    IF key=99 or key <> -1 AND key <10 THEN
      value:=IFTE(key=99,IP(value/10),value*10+key);
    END;
    IF key=20 THEN
    RECT_P(86,86,239,111);
    he:=1;
    //value:=0;
    END;
    IF key=21 THEN   // Symb Key sets value to 0
    value:=0;
    END;
 END;
 IF he=1 THEN
    w:=TEXTOUT_P(STRING(value,1),88,86,2,0,144,16777215);
    s:=CONVERT(value,"base",16);
    d:=GET(SIZE(s),1);
    h:="";
    FOR i FROM 1 TO d DO
    IF value>0 THEN
      h:=h+CHAR(hc[s[i]+1]);
    END;
    END;
    RECT_P(w,86,239,97);
    w:=TEXTOUT_P("HEX: "+h,88,100,2,0,144,16777215);


    RECT_P(w,100,239,111);
    RECT_P(w,100,w+9,111,0);
    key:=keys[WAIT(0)];
    IF key=100 THEN
      RETURN "#"+h+"h";
    END;
    IF key=99 or key <> -1 and key<19 THEN
      value:=IFTE(key=99,IP(value/16),value*16+key);
    END;
    IF key=20 THEN
    he:=0;
    END;
    IF key=21 THEN   // Symb Key sets value to 0
    value:=0;
    END;
 END;
  UNTIL ISKEYDOWN(4);  //ESC will exit
RETURN 46;  //one way to exit program with no apparent consequences
END;



RE: Entering the 'Edit Integer' window - matalog - 01-08-2024 01:12 AM

And a little bit shorter: (edited)

Code:
KEY KS_Minus()
BEGIN
  local hc="0123456789ABCDEF";
  local w, s, d, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,-1,15});
  keys[0]:=20;   //
  keys[1]:=21;
  keys[19]:=99;  //backspace
  keys[30]:=100; //enter
  local s,h,i,he;
 he:=0;
  RECT_P(80,80,240,146,0,16777215);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,16777215);
  TEXTOUT_P("ENTER => OK",88,130,1);
  REPEAT

    w:=IFTE(he=0,IFTE(value=0,88,TEXTOUT_P(STRING(value,1),88,86,2,0,144,167772​15)),TEXTOUT_P(STRING(value,1),88,86,2,0,144,16777215));
    s:=CONVERT(value,"base",16);
    d:=GET(SIZE(s),1);
    h:="";
    FOR i FROM 1 TO d DO
    IF he and value>0 THEN
      h:=h+CHAR(hc[s[i]+1]);
    END;
    IF he=0 THEN
      h:=h+CHAR(hc[s[i]+1]);
    END;
    END;
    RECT_P(w,81,239,97);
    IF he=0 THEN 
    RECT_P(w,86,w+9,97,0);
    END;
    w:=TEXTOUT_P("HEX: "+h,88,100,2,0,144,16777215);
    RECT_P(w,100,239,111);
    IF he=1 THEN
        RECT_P(w,100,w+9,111,0);
    END;
    key:=keys[WAIT(0)];
    IF key=100 THEN
      RETURN "#"+h+"h";
    END;
    IF key=99 or key <> -1 AND key <10+he*9 THEN
      value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
    END;
    IF key=20 THEN
    RECT_P(86,86,239,111);
    he:=NOT he;
    END;
    IF key=21 THEN   // Symb Key sets value to 0
    value:=0;
    END;

  UNTIL ISKEYDOWN(4);  //ESC will exit
RETURN 46;  //one way to exit program with no apparent consequences
END;



RE: Entering the 'Edit Integer' window - matalog - 01-08-2024 11:59 AM

And stopping the program run beyond it's limits.

It can handle numbers up to #FFFFFFFFF or 999999999999.

Apps switches between hex and dec input and symb resets to zero.

Code:
KEY KS_Minus()
BEGIN
  local hc="0123456789ABCDEF";
  local w, s, d, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,-1,15});
  keys[0]:=20;   //
  keys[1]:=21;
  keys[19]:=99;  //backspace
  keys[30]:=100; //enter
  local s,h,i,he,ov;
 he:=0;
  RECT_P(80,80,240,146,0,16777215);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,16777215);
  TEXTOUT_P("ENTER => OK",88,130,1);
  REPEAT

    w:=IFTE(he=0,IFTE(value=0,88,TEXTOUT_P(STRING(value,1),88,86,2,0,144,167772​15)),TEXTOUT_P(STRING(value,1),88,86,2,0,144,16777215));
    s:=CONVERT(value,"base",16);
    d:=GET(SIZE(s),1);
    h:="";
    FOR i FROM 1 TO d DO
    IF he=0  or he and value>0 THEN
      h:=h+CHAR(hc[s[i]+1]);
 //  RECT_P(80,200,240,220,16777215,16777215);
  // TEXTOUT_P(h,80,200,1);
    END;

    END;
    RECT_P(w,81,239,97);
    IF he=0 THEN 
    RECT_P(w,86,w+9,97,0);
    END;
    w:=TEXTOUT_P("HEX: "+h,88,100,2,0,144,16777215);
    RECT_P(w,100,239,111);
    IF he=1 THEN
        RECT_P(w,100,w+9,111,0);
    END;
    key:=keys[WAIT(0)];
    IF key=100 THEN
      RETURN "#"+h+"h";
    END;
    IF key=99 or key <> -1 AND key <10+he*9 THEN
      ov:=value;
      value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);

    
      IF value>999999999999 THEN
    value:=ov;
    END;
    END;
    IF key=20 THEN
    RECT_P(86,86,239,111);
    he:=NOT he;
    END;
    IF key=21 THEN   // Symb Key sets value to 0
    value:=0;
    END;

  UNTIL ISKEYDOWN(4);  //ESC will exit
RETURN 46;  //one way to exit program with no apparent consequences
END;



RE: Entering the 'Edit Integer' window - komame - 01-08-2024 07:35 PM

I've added some optimizations.

Code:
KEY KS_Minus()
BEGIN
  local hc="0123456789ABCDEF", white=16777215;
  local wd, wh, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,99,15});
  keys[0]:=20;
  keys[1]:=21;
  keys[30]:=100;
  local s,h,i,he=0,ov;

  RECT_P(80,80,240,146,0,white);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,white);
  TEXTOUT_P("DEC:",88,86,2,0); TEXTOUT_P("HEX:",88,100,2,0);
  TEXTOUT_P("APPS => base, ENTER => OK",88,130,1);

  REPEAT
    wd:=TEXTOUT_P(STRING(value,1),115,86,2,0,144,white);
    h:=CHAR(EXECON("hc[&1+1]",CONVERT(value,"base",16)));

    RECT_P(wd,81,239,97); // clear the space after DEC
    wh:=TEXTOUT_P(h,115,100,2,0,144,white);
    RECT_P(wh,100,239,111); // clear the space after HEX

    IF value = 0 THEN
      115▶wd▶wh;
    END;
    IF he THEN
      RECT_P(wh,100,wh+6,111,0);
    ELSE
      RECT_P(wd,86,wd+6,97,0);
    END;
    key:=keys[WAIT(0)];
    CASE
      IF key=100 THEN
        RETURN "#"+h+"h";
      END;
      IF key >= 0 AND key < 10+he*9 or key=99 THEN
        ov:=value;
        value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
        IF value>999999999999 THEN
          value:=ov;
        END;
      END;
      IF key=20 THEN // Apps changes the base
        he:=NOT he; //RECT_P(115,86,239,111); // unnecessary
      END;
      IF key=21 THEN   // Symb Key sets value to 0
        value:=0;
      END;
    END;
  UNTIL ISKEYDOWN(4);  //ESC will exit

  RETURN 46;  //one way to exit program with no apparent consequences
END;

I think we're not far from a solution where this could be turned into a real editor, with the ability to move the cursor across the digits (left and right) and edit them at specific positions.
I'm leaving for the whole day tomorrow, but if you don't get this sorted out by then, I'll take care of it the day after tomorrow Wink


RE: Entering the 'Edit Integer' window - matalog - 01-08-2024 10:49 PM

Something in the line

h:=CHAR(EXECON("hc[&1+1]",CONVERT(value,"base",16)));

Seems to be crashing the program as soon as it is run on my calcualtor.


RE: Entering the 'Edit Integer' window - matalog - 01-08-2024 11:14 PM

This is the same version reverted to the old way for h:= and working again, mainly so I have access to look at it in work tomorrow if I get time.

Code:
EXPORT intedit()
BEGIN
  local hc="0123456789ABCDEF", white=16777215;
  local wd, wh, key, keys=MAKELIST(-1,X,0,50), value;
  keys:=REPLACE(keys,32,{7,8,9,-1,-1,4,5,6,-1,-1,1,2,3,-1,-1,0});
  keys:=REPLACE(keys,14,{10,11,12,13,14,99,15});
  keys[0]:=20;
  keys[1]:=21;
  keys[30]:=100;
  local s,d,h="",i,he=0,ov;

  RECT_P(80,80,240,146,0,white);
  BLIT_P(80,61,241,81,G0,0,0,1,20);
  TEXTOUT_P("Edit Integer",123,62,3,white);
  TEXTOUT_P("DEC:",88,86,2,0); TEXTOUT_P("HEX:",88,100,2,0);
  TEXTOUT_P("APPS => base, ENTER => OK",88,130,1);

  REPEAT
    h:="";
    s:=CONVERT(value,"base",16);
    d:=GET(SIZE(s),1);
    wd:=TEXTOUT_P(STRING(value,1),115,86,2,0,144,white);
    FOR i FROM 1 TO d DO
      h:=h+CHAR(hc[s[i]+1]);
    END;

    RECT_P(wd,81,239,97); // clear the space after DEC
    wh:=TEXTOUT_P(h,115,100,2,0,144,white);
    RECT_P(wh,100,239,111); // clear the space after HEX

    IF value = 0 THEN
      115▶wd▶wh;
    END;
    IF he THEN
      RECT_P(wh,100,wh+6,111,0);
    ELSE
      RECT_P(wd,86,wd+6,97,0);
    END;
    key:=keys[WAIT(0)];
    CASE
      IF key=100 THEN
        RETURN "#"+h+"h";
      END;
      IF key >= 0 AND key < 10+he*9 or key=99 THEN
        ov:=value;
        value:=IFTE(key=99,IP(value/(10+6*he)),value*(10+6*he)+key);
        IF value>999999999999 THEN
          value:=ov;
        END;
      END;
      IF key=20 THEN // Apps changes the base
        he:=NOT he; //RECT_P(115,86,239,111); // unnecessary
      END;
      IF key=21 THEN   // Symb Key sets value to 0
        value:=0;
      END;
    END;
  UNTIL ISKEYDOWN(4);  //ESC will exit

  RETURN 46;  //one way to exit program with no apparent consequences
END;

KEY KS_Minus()
BEGIN
 intedit();
END;