Re: Sequence items to a single number ? How to achieve ?
- Posted by Selgor Feb 05, 2011
- 1137 views
Hello all
Thank you for staying with me
The following is the programme
It works as written
I am using eu 3.1 not eu 4
I would like to place the binary number in the edit box of window
You will see all that I have tried
None works
So how does the binary number "go" into the "box"
Cheers
Selgor
--------------------------------- NewNarA1.exw ............ work No.1. include Win32Lib.ew without warning ------------------------------------------------------------------------------- sequence seq -------------------------------------------------------------------------------- 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, 48, 20, 0, 0 ) , LText1 = createEx( LText, "Type Number and Enter", Window1, 45, 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() integer number,n1 seq = {} number=getNumber(EditText1) n1 = number while n1 != 0 do seq = prepend(seq, remainder(n1,2)) n1 = floor(n1/2) end while for i = 1 to length(seq) do -- seq += 48 --setText(EditText2,sprintf("%s",seq[i])) --printf(1,"%s\n",{seq}) -- puts(1,"Seq =") -- seq += 48 -- setText(EditText2,{"%s"} seq[i]) printf(1,"%d",seq[i]) end for --?{seq} -- setText(EditText2,sprintf("%s %d",{seq})) --/*Now as to the formatting of the output\\ --I thought you wanted to take a sequence such as {1, 0, 1, 1, 0, 1, 1} and print it out as '1011011' if so you would use --seq += 48 --printf(1,"%s\n",{seq}) --*/ -- setText(EditText2,{seq}) 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 )