Autor Beitrag
Tigu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Mi 08.03.06 15:54 
Hallo Ihr!

Ich würde gerne Zahlen, von denen ich nicht weiss, wie viele es sind, aus einer Listbox auslesen und hinterher addieren.
Kann mir jemand sagen, wie das geht?
Ich habe dazu noch gar keinen Quelltext, weil mir der Anfang fehlt.

Vielen Dank schon einmal für die Hilfe

Tigu
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mi 08.03.06 15:58 
Etwa so ! ungetestet
ausblenden Delphi-Quelltext
1:
for i := 0 to ListBox.Count -1 do ergebnis := ergebnis + StrToInt(ListBox[i]);					

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Hux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 171



BeitragVerfasst: Mi 08.03.06 15:59 
In einer for-Schleife:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
var i,x:integer;
begin
x:=0;
for i:=0 to ListBox1.ItemCount do begin
x:=x+StrToInt(LIstbox1.Items[i]);
end;


Hab grad kein Delphi zur Hand..., probiers mal aus!
Hux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 171



BeitragVerfasst: Mi 08.03.06 16:01 
@chrisw:
Zitat:
ausblenden Delphi-Quelltext
1:
for i := 0 to ListBox.Count -1 do ergebnis := ergebnis + StrToInt(ListBox[i]);					


--> Listbox[i] kann schonmal nicht funktionieren!
Tigu Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 93

XP
Delphi 7
BeitragVerfasst: Mi 08.03.06 16:13 
Hallo Hux!

Erst einmal Danke für die schnelle Hilfe.
Du schreibst:
ausblenden Delphi-Quelltext
1:
for i:=0 to ListBox1.ItemCount do begin					


kannst du mir sagen, was do mit ItemCount sagen willst? Delphi hat auch ein Problem damit.

Tigu
elron
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 34

WIN XP
D5 Standard
BeitragVerfasst: Mi 08.03.06 16:14 
so zumindest für delphi 5:
ausblenden Delphi-Quelltext
1:
for i := 0 to ListBox.Items.Count-1 do ergebnis := ergebnis + StrToInt(ListBox.Items[i]);					

_________________
JAJA, ich weiß, ich bin ein Anfänger...
Hux
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 171



BeitragVerfasst: Mi 08.03.06 16:16 
@Tigu:

Ich meinte Items.Count;
MightyPit
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 22

Win XP
Delphi 2005 pro, Delphi 7
BeitragVerfasst: Fr 10.03.06 11:00 
In delphi 7 kann man sich das Items sparen und tatsächlich Listbox.count bzw Listbox[i] verwenden. Zumindest wenn Listbox von TList abgeleitet ist.