Re: Set hex number in EditText box I only get last "number" D
- Posted by DerekParnell (admin) Feb 07, 2011
- 1271 views
Selgor said...
The programme converts decimal to hex
Works fine
But enter 429 decimal which is 1AD hex
All I get is a D
How do I get all of 1AD
I still don't understand why you continue to use double \\ in these posts, but oh well if you want to do things the harder way, that's your choice.
Anyhow, the reason you are getting that result is that you repeatedly set EditText2 to the digits in the result so naturally whatever is the last digit is what you'll end up with.
I'd do it very differently. First, I'd make dec_hex() a function and totally remove all UI elements from it. I'd write this ...
constant hexdigit = "0123456789ABCDEF" function dec_hex(object number) sequence seq integer digit seq = "" while 1 do digit = remainder(number, 16) seq = hexdigit[digit + 1] & seq number = floor( number/ 16) if number = 0 then exit end if end while return seq end function
Then in your UI handler you only need to do this ...
-------------------------------------------------------------------------------- procedure EditText1_onKeyDown (integer self, integer event, sequence params) if params[1]=13 then setText(EditText2, dec_hex(getNumber(EditText1)) setText(EditText1,"") setVisible(LText2,0) setVisible(LText6,0) else setText(EditText2, "") end if end procedure setHandler( EditText1, w32HKeyDown, routine_id("EditText1_onKeyDown"))