RE: Entering the 'Edit Integer' window
(01-08-2024 10:49 PM)matalog Wrote: 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.
The problem stemmed from the fact that the EXECON instruction did not work correctly with the local variable "hc" (it probably requires a global variable). I had a variable "hc" with the same content also declared in HOME, which is why it accidentally worked correctly on my device. After removing this variable from HOME, the problem indeed occurred. Then, when I replaced the "hc" variable in the program with the global list "L1", everything worked correctly. The lack of support for local variables in EXECON seems to be a bug, but I need to investigate it more thoroughly. Below is the working version based on the list L1.
Code:
KEY KS_Minus()
BEGIN
local 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;
L1:=ASC("0123456789ABCDEF");
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("L1[&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;
EDIT:
Another solution is to declare the variable "hc" as EXPORT in the header:
Code:
EXPORT hc:="0123456789ABCDEF";
then it will also work correctly with EXECON.
|