Post Reply 
Improved change of integer base
02-24-2014, 06:59 PM
Post: #4
RE: Improved change of integer base
Now the user input works, I created a small code snippet which can be used as more useful drop in replacement for the "drawmenu()" function (see also my other thread).
The on screen buttons now show the units in which the "Ans" value can be converted. If the user taps one unit, the converted value appears on the input line.
2 Problems remain:
1. I have to poll the mouse() value, which is not nice to the CPU.
2. If the user presses the a softbutton, the underlying softbutton of the system (e.g. "STO->" for the first softbutton in HOME view) is also pressed.
If you have answers to the question please post them in the thread regarding the code snippet. I think that's more useful there.

Code:

EXPORT DrawMenuSelect(buttonlabellist)
// Parameters: menustringlist is a list which should contain at most 6 strings for the button labels
// Returns: The ID (1 to 6) of the button that was pressed
BEGIN
 LOCAL selection, mouselist;
 DRAWMENU(buttonlabellist);
 FREEZE();
 WHILE MOUSE(1)<#DD:-16h DO END;//Wait until the screen is touched somewhere in the  verticle region of the soft keys
 mouselist:=MOUSE();

 selection:=CEILING((MOUSE(0)+1)*6/320); // Screen is 320px wide. There are six buttons. hence divide mouse value by 320/6. To avoid getting a value of zero when the user presses exactly at the left border a 1 is added to the mouse value

 RETURN selection;
END; 

EXPORT KEY K_Templ()
BEGIN
 LOCAL val, unit, conv, selection;
 val:=STRING(Ans);
 unit:=MID(val,INSTRING(val,"_"));
 CASE
  IF ((unit=="_(°C)") OR (unit=="_(°F)") OR (unit=="_(K)")) THEN conv :={"°C", "°F", "K"}; END;
  IF ((unit=="_(m)") OR (unit=="_(mm)") OR (unit=="_(cm)") OR (unit=="_(km)")) THEN conv :={"yd", "ft", "in", "mile"}; END;
  // IF THEN END; // insert cases for other common combinations here
  DEFAULT RETURN "Error: No conversion implemented for that.";
 END;
 selection:=DrawMenuSelect(conv);
 // save the selected destination unit in "unit" variable
 unit:=EXPR("1_(" + conv(selection) + ")"); 
 RETURN STRING(CONVERT(EXPR(val),unit));
END;

@Angus: I think this could easily adapted to achieve the base conversion you mentioned.
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 - Stefan - 02-24-2014 06:59 PM



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