Autor Beitrag
vatras
Hält's aus hier
Beiträge: 5



BeitragVerfasst: So 10.06.07 15:12 
Hallo,

Ich habe folgendes Problem bei einer eig. recht leichten IF Then Konstruktion:

Wenn Edit4 keinen Inhalt hat, soll die Variable test mit dem Wert 0 arbeiten.

Überlegung:

ausblenden Delphi-Quelltext
1:
If edit4.text=' ' then test:=0;					


Leider funktioniert, dass nicht so ganz. Das Programm rechnet dann nämlich nicht mit dem Wert 0 weiter.

Ich hoffe ihr könnt mir helfen.
Danniolo
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 693



BeitragVerfasst: So 10.06.07 15:15 
Jetzt fragst du ab, ob das Edit ein Leerzeichen enthält..

Korrekt sollte es heißen:


ausblenden Delphi-Quelltext
1:
2:
If Trim(Edit4.Text) = '' then 
  test:=0;


Zuletzt bearbeitet von Danniolo am So 10.06.07 15:21, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 10.06.07 15:17 
Moin und :welcome: im Forum!

user profile iconvatras hat folgendes geschrieben:
Wenn Edit4 keinen Inhalt hat, soll die Variable test mit dem Wert 0 arbeiten.

Zwei mögliche Lösungen: ;)

a) test := StrToIntDef(Edit4.Text,0);
Wenn Edit4.Text sich nicht in eine Zahl umwandeln lässt, wird der Vorgabewert 0 genommen. :idea:

b)
ausblenden Delphi-Quelltext
1:
2:
if (Trim(Edit4.Text) = ''then
  test := 0;

Trim() entfernt führende und folgende Leerzeichen und Vergleichen musst du natürlich mit einem Leerstring! ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
vatras Threadstarter
Hält's aus hier
Beiträge: 5



BeitragVerfasst: So 10.06.07 15:38 
Danke für eure Hilfe! Es läuft nun perfekt ;)

//Edit:

Ich habe noch ein Problem bei meinem Programm (was den Notendurchschnitt berechnen soll):

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:
38:
39:
40:
41:
42:
var
  Form1: TForm1;
  var eng,ma,de,lat,franz,span,bio,ch,ph,poli,ge,edk,mu,ku,sp,inf,ds,anzahl,gesamt : integer ;
  notendurchschnitt : real;

implementation

{$R *.dfm}



procedure TForm1.Button1Click(Sender: TObject);
begin
 eng:=strtoint (edit1.text)  ;
 de:=strtoint (edit2.text)    ;
 ma:=strtoint (edit3.text)    ;
 lat:=StrToIntDef(Edit4.Text,0);
 franz:=StrToIntDef(Edit5.Text,0);
 span:=StrToIntDef(Edit6.Text,0);
 bio:=StrToIntDef(Edit8.Text,0);
 ch:=StrToIntDef(Edit9.Text,0);
 ph:=StrToIntDef(Edit10.Text,0);
 poli:=StrToIntDef(Edit11.Text,0);
 ge:=StrToIntDef(Edit12.Text,0);
 edk:=StrToIntDef(Edit13.Text,0);
 mu:=StrToIntDef(Edit14.Text,0);
 ku:=StrToIntDef(Edit15.Text,0);
 sp:=StrToIntDef(Edit16.Text,0);
 inf:=StrToIntDef(Edit17.Text,0);
 ds:=StrToIntDef(Edit18.Text,0);
 anzahl:=18;
 if lat=0 then anzahl-1;
 if franz=0 then anzahl-1 ;
 if span=0 then anzahl-1   ;
 if ch=0 then anzahl-1      ;
 if ku=0 then anzahl-1       ;
 if mu=0 then anzahl-1        ;
 if ds=0 then anzahl-1         ;
 if inf=0 then anzahl-1         ;
 gesamt:=eng+ma+de+lat+franz+span+bio+ch+ph+poli+ge+edk+mu+ku+sp+inf+ds   ;
 notendurchschnitt:=gesamt/anzahl;
 edit7.text:=floattostr (notendurchschnitt) ;


und zwar kommt es nicht zum Start wegen folgender Fehlermeldung: "Anweisung erforderlich, aber Ausdruck vom Typ "Integer" gefunden!"

Mir ist schon klar, wie es zu diesem Fehler kommt. Nur weiß ich keine Alternative!

Ich bitte nochmal um eure Hilfe^^