Autor Beitrag
anno2007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mo 28.01.08 18:25 
Hi,
ich hab ein Problem mit IF und THEN :cry: :

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
var
  Form1: TForm1;
  l, i, j, k  : integer;
  s, ch, ausgabe : string;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
s:= edit1.text;
l:=length(s);

if l <= 9 then begin
   for i := 1 to l do begin
   ch:='             ' +  copy(s,i,1);
   Ausgabe:=format('Nr.  %5d:%4s',[i,ch]) ;
   ListBox1.items.add(ausgabe);
end;


if l > 9 then begin
   for j := 1 to 9 do begin
   ch:='             ' +  copy(s,i,1);
   Ausgabe:=format('Nr.  %5d:%4s',[i,ch]) ;
   ListBox1.items.add(ausgabe);
end;

   for k:= 9 to l do begin
   ch:='            ' +  copy(s,i,1);
   Ausgabe:=format('Nr.  %5d:%4s',[i,ch]) ;
   ListBox1.items.add(ausgabe);
end;


Es wird immer nur das erste IF beachtet. Wenn ich jetzt das Programm starte funktioniert es nur wenn die länge also l kleiner oder gleich 9 ist.
Wenn ich die 2 IF-Strukturen vertausche funktionierts nur, wenn l größer ist als 9.
Kann mir vielleicht jemand sagen was ich falsch mache?

Danke,
anno2007
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mo 28.01.08 18:30 
Hallo, user profile iconanno2007!

Ich würde dir erst einmal eine übersichtliche Code-Formatierung empfehlen. Dann würde dir nämlich auffallen, dass da einige end; fehlen. Wo, darfst jetzt du herausfinden :mrgreen:

Mich wundert allerdings, dass der Code überhaupt compiliert wird :nixweiss:

Grüße,
Yogu
anno2007 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mo 28.01.08 18:37 
Hi,
danke erstma für die Antwort, ich bin ein kompletter noobie im Programmieren, unn hab auch grad erst angefangen, wie könnt ich den Code so umgestalten, das er in einer "lesbaren Form" ist?

Ich weiß auch ned, auf jeden Fall wird er compiliert. :D

Außerdem, meckert der Compiler ned normal, wenn end; 's fehlen?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Mo 28.01.08 18:42 
Hallo!

Ich habe Deinen Code mal formatiert. Da siehst Du dann, wo noch was fehlt bzw. falsch ist ;-)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
var
  Form1: TForm1;
  l, i, j, k  : integer;
  s, ch, ausgabe : string;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
  s:= edit1.text;
  l:=length(s);

  if l <= 9 then
  begin
    for i := 1 to l do
    begin
      ch:='             ' +  copy(s,i,1);
      Ausgabe:=format('Nr.  %5d:%4s',[i,ch]) ;
      ListBox1.items.add(ausgabe);
    end;
    if l > 9 then
    begin
      for j := 1 to 9 do
      begin
        ch:='             ' +  copy(s,i,1);
        Ausgabe:=format('Nr.  %5d:%4s',[i,ch]) ;
        ListBox1.items.add(ausgabe);
      end;

      for k:= 9 to l do
      begin
        ch:='            ' +  copy(s,i,1);
        Ausgabe:=format('Nr.  %5d:%4s',[i,ch]) ;
        ListBox1.items.add(ausgabe);
      end;


Grüße
Christian

P.S.: Könnte Dir helfen: crashkurs.christian-stelzmann.de
P.P.S.: Dass der kompiliert kann ich mir kaum vorstellen :gruebel:

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
anno2007 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mo 28.01.08 18:50 
is aber so :D
anno2007 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 68

Win 7, Ubuntu
Delphi XE
BeitragVerfasst: Mo 28.01.08 18:51 
€: sry