1. A new line may give correct printout ?? How ?

hello

Selgor here

The following programme is to print out after calculation

Pascal's Triangle

1
1 1
1 2 1
1 3 3 1 etc

But it ain't playing the game as it did in .ex code

I think I need a new line structure which used to be

"\n" embedded in printf statement
Any help accepted
It prints as a triangle the numbers but doesn't show as such in this post ??
Cheers

Selgor

The programme :=

----------------------------------  PasTri--------------------- 
 
include Win32Lib.ew 
without warning 
 
sequence CoEff     CoEff = repeat(0,20)   -- Initialise Sequence..20 zeroes 
                   CoEff[2] = 1           -- Initialise Triangle Start 
object   number,Request,across ,down 
 
global constant  Window1  = create(Window,"",0,150,150,610,415,{WS_POPUP,WS_DLGFRAME}) 
                                   setWindowBackColor(Window1,Parchment) 
global constant LText1 = createEx( LText, "Type a Number and Enter", Window1, 120, 10, 132, 20, 0, 0 ) 
global constant EditText1 = createEx( EditText, "", Window1, 250, 10, 88, 20, 0, 0 ) 
global constant LText4 = createEx( LText, "Press Enter to Restart", Window1, 450, 50, 150, 20, 0, 0 ) 
 
procedure draw_it() 
 
   sequence CoEff 
   object   number,Request 
   CoEff = repeat(0,20)   -- Initialise Sequence..20 zeroes 
   CoEff[2] = 1           -- Initialise Triangle Start 
   number=getNumber(EditText1) 
   Request = number + 1   -- Avoid Zero 
   across = 300        -- Where 1st row is  to start 
   down = 70 
   for Row = 1 to Request do 
      for i = 0 to across do    -- Pseudo Tab Function 
         wPuts({Window1,across,down},"  ") 
      end for 
      for Col = Row to 2 by -1 do 
	CoEff[Col] = CoEff[Col] + CoEff[Col-1] 
        wPuts({Window1,across,down},{"%8d",CoEff[Col]}) 
      end for 
      down    += 10          -- Move down 
      across  -= 20          -- Move left 
 
      -- puts(1,"\n")       -- New line twice spacing triangle 
      -- puts(1,"\n")       --       in a readable way 
   end for 
end procedure 
 
procedure EditText1_onKeyDown (integer self, integer event, sequence params) 
    if params[1]=13 then 
       if self=EditText1 then 
          doEvents(0) 
          draw_it() 
          setFocus(EditText1) 
          setText(EditText1,"") 
       end if 
    end if 
 
end procedure 
setHandler( {EditText1}, w32HKeyDown, routine_id("EditText1_onKeyDown")) 
 
-------------------------------------------------------------------------------- 
procedure Window1_onActivate (integer self, integer event, sequence params)--params is () 
  setVisible(LText4,0) 
  setFocus(EditText1) 
  setPenColor( Window1, Green ) 
  setPenWidth( Window1, 8 ) 
  drawRectangle( Window1, w32False, 2, 50, 602, 408) 
end procedure 
setHandler( Window1, w32HActivate, routine_id("Window1_onActivate")) 
-------------------------------------------------------------------------------- 
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 ) 
 
new topic     » topic index » view message » categorize

2. Re: A new line may give correct printout ?? How ?

Four little changes (marked with --<<) should make you happy:

procedure draw_it()  
integer x                                                       --<< 
   sequence CoEff  
   object   number,Request  
   CoEff = repeat(0,20)   -- Initialise Sequence..20 zeroes  
   CoEff[2] = 1           -- Initialise Triangle Start  
   number=getNumber(EditText1)  
   Request = number + 1   -- Avoid Zero  
   across = 300        -- Where 1st row is  to start  
   down = 70  
   for Row = 1 to Request do  
      for i = 0 to across do    -- Pseudo Tab Function  
         wPuts({Window1,across,down},"  ")  
      end for  
      x = 0                                                     --<< 
      for Col = Row to 2 by -1 do  
        CoEff[Col] = CoEff[Col] + CoEff[Col-1]  
        wPuts({Window1,across+x,down},{"%8d",CoEff[Col]})       --<< 
        x += 40                                                 --<< 
      end for  
      down    += 10          -- Move down  
      across  -= 20          -- Move left  
  
      -- puts(1,"\n")       -- New line twice spacing triangle  
      -- puts(1,"\n")       --       in a readable way  
   end for  
end procedure 

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

3. Re: A new line may give correct printout ?? How ?

Hello Pete

Thanks for the mend

The added lines work perfectly

So, I just did not give room for the numbers to "move"

Is that correct ??

O.K. on with the next 20 odd .ex to .exw I will go

Oh what "fun"

Cheers

Selgor

new topic     » goto parent     » topic index » view message » categorize

4. Re: A new line may give correct printout ?? How ?

Selgor said...

Thanks for the mend

The added lines work perfectly

So, I just did not give room for the numbers to "move"

Is that correct ??

Yes. For completeness, some other changes:

--global constant LText4 = createEx( LText, "Press Enter to Restart", Window1, 450, 50, 150, 20, 0, 0 )  
  
procedure draw_it()  
   for Row = 1 to Request do  
--    for i = 0 to across do    -- Pseudo Tab Function 
--       wPuts({Window1,across,down},"  ")  
--    end for  
end procedure  
  
procedure EditText1_onKeyDown (integer self, integer event, sequence params)  
       if self=EditText1 then  
          repaintWindow(Window1)                                 --<< 
          drawRectangle( Window1, w32False, 2, 50, 602, 408)     --<< 
end procedure  
 
procedure Window1_onActivate (integer self, integer event, sequence params)--params is ()  
--  setVisible(LText4,0)  
end procedure  

IE: remove LText4 and the "Pseudo Tab Function", and add a repaint and redraw the rectangle to clear previous contents.

Regards,
Pete

new topic     » goto parent     » topic index » view message » categorize

5. Re: A new line may give correct printout ?? How ?

Hello Pete

Not only a great helper but Pete Lomax is a mind reader Thank you heaps for the added code

When I ran the 1st 4 additional new code
the screen "screwed" up. My initial code NOT yours

I added clearwindow etc to clear old and though still workable "look" wasn't good

So, I was going to post again and then thought I would make do

And now you have done this for me

Well and truly up to .exw standard.

Greatly appreciated

Thank you for time and patience

Look out .. still got 20 odd to go

But it is "fun"

Cheers

Selgor

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu