1. Set hex number in EditText box I only get last "number" D
- Posted by Selgor Feb 06, 2011
- 1375 views
Hello
Selgor here
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 have tried a lot of code as you can see
Please any suggestions ?
Cheers
Selgor
--------------------------------- Decimal to Hex ............ Version 1.22 include Win32Lib.ew without warning global constant Window1 = create(Window,"",0,120,150,610,95,{WS_POPUP,WS_DLGFRAME}) setWindowBackColor(Window1,Parchment) -------------------------------------------------------------------------------- global constant EditText1 = createEx( EditText, "", Window1, 180, 10, 48, 20, 0, 0 ) , EditText2 = createEx( EditText, "", Window1, 180, 48, 148, 20, 0, 0 ) , LText1 = createEx( LText, "Type Decimal Number and Enter", Window1, 5, 10, 170, 20, 0, 0 ), LText2 = createEx( LText, "OR", Window1, 480, 40, 170, 20, 0, 0 ), LText5 = createEx( LText, "Left Click Window to exit", Window1, 400, 70, 192, 20, 0, 0 ), LText6 = createEx( LText, "Hit Enter for another No.", Window1, 400, 10, 192, 20, 0, 0 ), LText7 = createEx( LText, "Your Hexadecimal Number --->> ", Window1, 5, 50, 170, 20, 0, 0 ) setFont(LText2,"Times Roman",12,Italic+Bold) setFont(LText5,"Times Roman",12,Italic+Bold) setFont(LText6,"Times Roman",12,Italic+Bold) --------------------------------------------------------------------------------------------------- procedure dec_hex() sequence seq object number,n1,no,m,i,times seq = {} m = 1 no=0 i=0 times = 0 number=getNumber(EditText1) n1 = number while n1 != 0 do times +=1 seq = prepend(seq, remainder(n1,16)) n1 = floor(n1/16) -- seq += 48 --setText(EditText2, sprintf("%d", {seq})) --seq += 48 setText(EditText2,sprintf("%10x",seq[times])) --setText(EditText2,sprintf("%x",{seq})) end while for j = 1 to times do -- sprintf(1,"%x",{seq}) setText(EditText2,sprintf("%x",seq[j])) end for -- ?seq setVisible(LText2,1) setVisible(LText6,1) end procedure ---------------------------------------------------------------------------------- procedure Window1_onActivate (integer self, integer event, sequence params) setVisible(LText2,0) setVisible(LText6,0) setFocus(EditText1) end procedure setHandler( Window1, w32HActivate, routine_id("Window1_onActivate")) -------------------------------------------------------------------------------- procedure EditText1_onKeyDown (integer self, integer event, sequence params) if params[1]=13 then if self=EditText1 then doEvents(0) dec_hex() elsif self=EditText2 then setText(EditText1,"") setText(EditText2,"") setVisible(LText2,0) setVisible(LText6,0) end if end if end procedure setHandler( {EditText1,EditText2 }, w32HKeyDown, routine_id("EditText1_onKeyDown")) ------------------------------------------------------------------------------------------- procedure CloseApp ( integer self, integer event, sequence parms ) if self = Window1 then closeWindow(Window1) closeApp() end if end procedure setHandler(Window1, w32HClick, routine_id("CloseApp")) --------------------------------------------------------------------------------------------- WinMain( Window1,Normal )
2. Re: Set hex number in EditText box I only get last "number" D
- Posted by DerekParnell (admin) Feb 07, 2011
- 1362 views
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"))
3. Re: Set hex number in EditText box I only get last "number" D
- Posted by Selgor Feb 07, 2011
- 1312 views
Hello Derek
As usual you repaired the code.And for that I am grateful once again.It works well.
Except for 1 thing that threw me .Derek, an error! Never! Yet there was. But rectified. So all is well. It was here.
setText(EditText2, dec_hex(getNumber(EditText1))
Need an extra ) at the end of the line. Anyway all is well . As I said. It works. Would you believe I knew to put it in.
About the double line thing at the end of a line in a post
I thought one had to put the double lines at the end of a line Well I learn something new everyday.
I hope you are not affected by the floods in Victoria. Terrible there & Queensland.
And boy did I learn something with your code ... WOW .
Thanks again Derek for your time, patience, and generosity of giving your code.
All the best. But , I still have a few to go.
One last "thing" . Is it experience to know to use a function or what ??
Cheers.
Selgor.