Autor Beitrag
Abu36
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Do 16.03.06 16:23 
hi,

ich hab mal eine frage :?:


also ich habe 3 stringgrids mit je 5 mal 5 feldern. zum überprüfen der einträge soll die erste zeile, also die oberen 5 felder von jedem stringgrid addiert werden und eine bestimmte summe rauskommen. in den feldern stehen zahlen, die eingegeben werden können. zum beispiel sollen die zellen [0,0] bis [4,0] von jedem stringgrid addiert werden.
wenn die addition aller felder in der reihe erfolgt ist soll das ergebnis 125 sein. wenn es größer oder kleiner als 125 ist, soll in einem panel dann stehn: falsch.

könnt ihr mir helfen
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 16.03.06 16:42 
du deklarierst dir ne integer-variable, in der du die einzelnen werte zusammenzählst, dann prüfst du mit if diese variable

ausblenden Delphi-Quelltext
1:
2:
3:
if variable = 125 then
  panel1.caption:='richtig';
else panel1.caption:='falsch';
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 16.03.06 16:55 
das ganze als prozedure, damit du nicht alles 3x schreiben musst :)
(miri, vor else kein semikolon!;) )

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure ZAddition(var StringGrid: TStringgrid; Panel: TPanel);
var zahl: byte;
begin
zahl := 0;
 for zelle := 0 to 4 do
   zahl := zahl + StrToInt(stringgrid.Cells[zelle,0]);

 if zahl = 125 then
  panel.caption:='richtig'
   else
    panel.caption:='falsch';
end;
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 16.03.06 17:01 
hast ja recht *g*

hab doch nur so mal eben runtergeschrieben.. hab auffer arbeit ja nich ma delphi zur hand :(

aber so wars gemeint *g*
Abu36 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Do 16.03.06 17:16 
funktioniert irgendwie nich

ausblenden Delphi-Quelltext
1:
2:
3:
4:
for a:=0 to stringgrid1.ColCount-1 do  {a ist variable für erste reihe im ersten stringgrid}                
  for aa:=0 to stringgrid2.ColCount-1 do     {aa ist variable für erste reihe im ersten stringgrid}
     for aaa:=0 to stringgrid3.ColCount-1 do     {aaa ist variable für erste reihe im ersten stringgrid}
          r1:=strtoint((stringgrid1.Cells[a,0]) + (stringgrid2.Cells[aa,0]) + (stringgrid3.Cells[aaa,0])); {r1 soll nun die werte aus den einzelnen stringgrids addieren, das funktioniert so aber irgenwie nich}
[/code][/xml]
Abu36 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Do 16.03.06 17:27 
also ich habs jetzt soweit, wie NoTVerYEvilPzYchO es geschrieben hat. mein problem ist aber, dass nicht nur die erste reihe aus einem stringgrid, sondern aus drei stringgrids addiert werden soll. also, wie verbinde ich die addition der stringgrids?
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Do 16.03.06 17:28 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure ZAddition(StringGrid1,StringGrid2,StringGrid3: TStringGrid; Panel: TPanel);
var zahl: byte;
begin
zahl := 0;
 for zelle := 0 to 4 do
   zahl := zahl + (StrToInt(stringgrid1.Cells[zelle,0]) + StrToInt(Stringgrid2.cells[zelle,0]) + StrToInt(StringGrid3.Cells[zelle,0]));

 if zahl = 30 then
  panel.caption:='richtig'
   else
    panel.caption:='falsch';
end;


:roll:
klappt bei mir :)
Abu36 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 59



BeitragVerfasst: Do 16.03.06 17:31 
juhu, jetzt gehts, danke. bis zur nächsten frage