Re: Set hex number in EditText box I only get last "number" D

new topic     » goto parent     » topic index » view thread      » older message » newer message
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"))  
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu