Autor Beitrag
Waldkauz
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Mo 30.03.09 22:45 
So, ich habe euch hier sicher schon den letzten Nerv geraubt, aber ich lass einfach bei meinem Projekt nicht locker.
Es ist jetzt programmtechnisch fertig, der letzte Feinschliff fehlt aber noch -
im Edit14 werden die Punkte, bzw. die Werte von Edit9, Edit10 usw. zusammengezählt.
Das Problem ist, wenn jetzt ein, oder mehrere Felder leer ist/sind,weil es keine Punkte gibt, will er das nicht zusammenrechnen (" '' ist kein gültiger Integerwert" - habs aber auch schon mit Null probiert)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
//den oberen Teil kennt ihr ja schon ...
      while not EoF(Pflanze) do
      begin
      ReadLn(Pflanze,Search);
        if (Edit5.Text=Search) and (StrToInt(Label9.Caption)>=100then
        Edit12.Text:='30';
        if (Edit5.Text=Search) and (StrToInt(Label9.Caption)>=60and (StrToInt(Label9.Caption)<100then
        Edit12.Text:='20';
        if (Edit5.Text=Search) and (StrToInt(Label9.Caption)>=0and (StrToInt(Label9.Caption)<60then
        Edit12.Text:='10';
        if Edit5.Text='' then
        Edit12.Text:='';  
      end;
      Closefile(Pflanze);
      Edit14.Text:= IntToStr(StrToInt(Edit8.Text)+StrToInt(Edit9.Text)+
      StrToInt(Edit10.Text)+StrToInt(Edit11.Text)+StrToint(Edit12.Text));
ImbaPanda
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 98

Windows XP/Vista
Delphi 7 Professional/ Rad Studio 2009
BeitragVerfasst: Mo 30.03.09 22:49 
Du musst vor der Berechnung lediglich überprüfen, ob alle Felder gefüllt sind.
ausblenden Delphi-Quelltext
1:
2:
3:
If (Edit9.Text<>''And (Edit10.Text<>''And ... Then
  //Zusammenrechnen
Else ShowMessage('Es Müssen alle Felder ausgefüllt sein');


Zuletzt bearbeitet von ImbaPanda am Mo 30.03.09 22:49, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 30.03.09 22:49 
Moin!

Schau dir mal StrToIntDef() in der DOH an. :idea: ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
jfheins
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 918
Erhaltene Danke: 158

Win 10
VS 2013, VS2015
BeitragVerfasst: Mo 30.03.09 22:50 
Benutze StrToIntDef() - damit kannst du einen Defaultwert angeben, falls der String (aslo der Text im Edit) kein gültiger Integerwert ist ;)

Also StrtointDef(Edit4.Text, 0) gibt 0 zuück wenn im Edit nichts steht ;)
Waldkauz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Mo 30.03.09 22:52 
user profile iconImbaPanda hat folgendes geschrieben Zum zitierten Posting springen:
Du musst vor der Berechnung lediglich überprüfen, ob alle Felder gefüllt sind.
ausblenden Delphi-Quelltext
1:
2:
3:
If (Edit9.Text<>''And (Edit10.Text<>''And ... Then
  //Zusammenrechnen
Else ShowMessage('Es Müssen alle Felder ausgefüllt sein');


nein, in Edit9 und Edit10 kommen ja die Punkte, die man für das Geschriebene bekommt.
Und, es kann ja auch sein, dass man keinen Punkt für ein Wort bekommt - dann muss Edit9 bzw Edit 10 usw. ja leer bleiben oder eine Null drin stehen...
Waldkauz Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 102



BeitragVerfasst: Mo 30.03.09 22:55 
user profile iconjfheins hat folgendes geschrieben Zum zitierten Posting springen:
Benutze StrToIntDef() - damit kannst du einen Defaultwert angeben, falls der String (aslo der Text im Edit) kein gültiger Integerwert ist ;)

Also StrtointDef(Edit4.Text, 0) gibt 0 zuück wenn im Edit nichts steht ;)


Funktioniert :)
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 30.03.09 22:57 
Wobei TryStrToInt vielleicht besser wäre, denn das gibt zurück, ob die Umwandlung erfolgreich war. Was, wenn bei StrToIntDef die Null im Edit steht? ;-)