Autor Beitrag
hibbert
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: So 22.12.02 23:10 
Hallo,

in einer Listbox sind 100% nur Zahlen vorhanden. Ein Label soll die sume anzeigen, unabhängig, wieviel Items die Listbox enthält. Kann mir einer weiterhelfen?

Jetztschonmal DANKE !

mfg hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 22.12.02 23:13 
In einer for-Schleife die Items durchgehen, zu einem Integer konverteiren und aufsummieren.
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 23.12.02 10:05 
Hallo Hibbert,

sollte ungefähr so funktionieren:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Var
  Sum: Integer;
  Idx: Integer;
Begin
  Sum := 0;
  For Idx := 0 To ListBox1.Items.Count -1 Do
    Sum := Sum + StrToInt (ListBox1.Items [Idx]);

  Label1.Caption := IntToStr (Sum);
End;


Gruß
TINO


Zuletzt bearbeitet von Tino am Mo 23.12.02 14:03, insgesamt 1-mal bearbeitet
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mo 23.12.02 13:57 
hallo,
vielen dank für die schnelle antowrt, aber da ist ein fehler im quellcode
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
Var 
  Sum: Integer; 
  Idx: Integer; 
Begin 
  Sum := 0; 
  For Idx := 0 To ListBox1.Items.Count -1 Do 
    Sum := Sum + StrToInt (ListBox1.items[Idx]); 
  Label1.Caption := IntToStr (Sum); 
End;
aber hat geklappt ! DANKE !
aber wie sieht es mit kommerzahlen aus ? z.B. 1,50 bzw 1.50 ?
geht das auch??

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mo 23.12.02 14:04 
hibbert hat folgendes geschrieben:
aber da ist ein fehler im quellcode

Stimmt. Habs geändert!

hibbert hat folgendes geschrieben:
aber wie sieht es mit kommerzahlen aus ? z.B. 1,50 bzw 1.50 ? geht das auch??

Ausprobieren :-D

Gruß
TINO
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 23.12.02 14:49 
StrToFloat
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mo 23.12.02 16:50 
hallo,
danke Luckie, aber StrToFloat ist für mich etwas ganz neues ! :shock:
Damit habe ich vorher noch nie gearbeitet, und in der online hilfe hab ich nichts gefunden, was mir weiterhilft... :(
wie muss ich denn dann die variable bezeichnen? (bei einer zahl ist es ja var a:integer;).
und muss ich einfach strtoint durch StrToFloat ersetzen.
wäre nett, wenn du mich aufklären könntest !
mfg hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 23.12.02 18:19 
also StrToFloat wandelt den string in einem Float wert um. ein folat wert ist ein wert,der auch kommazahlen enthalten kann !!!

bei var musst du dann die variable statt mit integer mit real deklarieren !!!

_________________
In the beginning was the word.
And the word was content-type: text/plain.
hibbert Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1007

WinServer2003, Win XP, Linux
D6 Pers, D05
BeitragVerfasst: Mo 23.12.02 19:31 
Vielen Dank für eure Hilfe !!!

Merry X Mas euch allen ! :wink:
mfg hibbert

_________________
I kunnen väl svara endast ja eller nej
Om i viljen eller nej