Recent

Author Topic: Program created by the memo  (Read 2401 times)

godik

  • New Member
  • *
  • Posts: 23
Program created by the memo
« on: November 21, 2018, 06:53:26 pm »
Hello I have to create a memo program using Memo,Label,Edit,Button.It has to show up on the memo and it has to be number between:(x>40) and (x<=120)




procedure TForm1.Button1Click(Sender: TObject);
var n,i,x:integer;
  begin
    n:=StrToInt(Edit1.Text);
    for i:=1 to n do
    if i mod (40=40) and (120=120) then Memo1.lines.add(IntToStr(i));

end;


end.         



Any help appreciated!
« Last Edit: November 21, 2018, 06:57:45 pm by godik »

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: Program created by the memo
« Reply #1 on: November 21, 2018, 07:44:21 pm »
Hello I have to create a memo program using Memo,Label,Edit,Button.It has to show up on the memo and it has to be number between:(x>40) and (x<=120)

procedure TForm1.Button1Click(Sender: TObject);
var n,i,x:integer;
  begin
    n:=StrToInt(Edit1.Text);
    for i:=1 to n do
    if i mod (40=40) and (120=120) then Memo1.lines.add(IntToStr(i));
end;

end.         

Any help appreciated!

That code doesn't make sense and won't even compile (did you try?).

In the first place the syntax for mod is: number MOD number and it returns an integer: "i mod (40=40) ..." is a very obvious syntax error.

In the second place, why are you even using mod? MOD is the complement to div; it returns the remainder of an integer division. But, as you said, all you need is to know whether "(x >40) and (x <= 120)" so, what's wrong with this code then?

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   n, i {, x never used!}: integer;
  4. begin
  5.   n:=StrToInt(Edit1.Text);
  6.   if n <= 40 then Exit; { No point to follow further!!! }
  7.   for i:=1 to n do
  8.     if (i > 40) and (i <= 120) then
  9.       Memo1.lines.add(IntToStr(i));
  10. end;

Do note that this is (almost) a mere restatement of your code. It can be made quicker and more robust.The "if n < 40 ..." is just an example to get you going. :)
« Last Edit: November 21, 2018, 07:55:57 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

godik

  • New Member
  • *
  • Posts: 23
Re: Program created by the memo
« Reply #2 on: November 21, 2018, 07:51:52 pm »
Thanks I  forgot to write that the code which I did was not correct ::)

 

TinyPortal © 2005-2018