New Thread Single items to number for Edit "Box" Solved
- Posted by Selgor Feb 06, 2011
- 3096 views
Hello
Selgor here
The following programme achieves the following goal
To get units of a sequence and make a "number"
Then enter the number in the appropriate "box"
It works for me using
eu 3.1 and my w32Lib
Thanks to all for reading the original post
and in particular to
Lnettnay , evanmars , WJ1N
Each gave me code to produce the final result
I worked the 3 lines to get the units as a single number
and the rest of the "trimmings"
Any constructive comments appreciated
Once again many thanks L , e , W
Cheers
Selgor
--------------------------------- Decimal to Binary ............ Version 1.12 -------------------------------- Many thanks to Lnettnay -------------------------------- also evanmars -------------------------------- also WJ1N -------------------------------------------------------------------------------- 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 Binary 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_bin() sequence seq object number,n1,no,m,i seq = {} m = 1 no=0 i=0 number=getNumber(EditText1) n1 = number while n1 != 0 do seq = append(seq, remainder(n1,2)) n1 = floor(n1/2) i+=1 -----<----- 1 no = no + (seq[i]*m) -----<----- 2 m = m * 10 -----<----- 3 3 lines makes seq units a "number" end while setText(EditText2,sprintf("%d",no)) -----<<----**** Puts Binary Mumber in "Box" setVisible(LText2,1) setVisible(LText6,1) end procedure ---------------------------------------------------------------------------------- procedure Window1_onActivate (integer self, integer event, sequence params) --params is () 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) --params is ( atom scanCode, atom shift ) if params[1]=13 then if self=EditText1 then doEvents(0) dec_bin() 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 )