Autor Beitrag
Florian.K
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 12.02.06 16:51 
Ein Hallo an die Delphi Community!
Um es direkt auf den Punkt zu bringen, ich habe ein Editfeld und eine Listbox. In dieser Listbox befinden sich 4 Zahlen. In einem Editfeld habe ich Beispielsweise die 4 oder die 5 als Eingabewert.
Doch wie kriege ich es hin das die die ZAhlen in der Listbox addiert werden und
meinem EdtEingabewert dazugerechnet werden.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 12.02.06 16:56 
Hallo,

mit einer For-To-Do Schleife.

So ungefähr

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var i:integer //das muss LOKAL deklariert werden

erg:=0;
for i := 0 to listbox1.items.count-1 do
begin
  erg:=erg+strtoint(listbox1.items[listbox1.itemindex]);
end;
erg:=erg+strtoint(edit1.text);
showmessage('Das Ergebnis ist +'inttostr(erg));

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Florian.K Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 12.02.06 17:08 
Ja aber wie kann ich das am besten in meinen QT einbauen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var i,Zahl,E:Integer;
begin
Zahl:=StrToInt(edtEingabewert.text);
For i := 1 To 4 do
 begin
 E:=i+Zahl;
 sleep(100);
  Listbox.Items.Add(IntToStr(E));
  Listbox.Refresh;
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 12.02.06 17:13 
user profile iconFlorian.K hat folgendes geschrieben:
Ja aber wie kann ich das am besten in meinen QT einbauen.
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
var i,Zahl,E:Integer;
begin
Zahl:=StrToInt(edtEingabewert.text);
For i := 1 To 4 do
 begin
 E:=i+Zahl;
 sleep(100);
  Listbox.Items.Add(IntToStr(E));
  Listbox.Refresh;


Der Code tut aber in keinster Weise das, was du vorhast :gruebel: (oder ich habe dein Vorhaben net gecheckt)

Die Zeile versteh ich nicht:

ausblenden Delphi-Quelltext
1:
 E:=i+Zahl;					


Warum fügst du i zum Ergebnis hinzu?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Florian.K Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 12.02.06 17:18 
Srry habe ich vergessen zu erwähnen. Ich gebe in mein Editfeld z.b 4 ein dann erscheint in meiner Listbox
5
6
7
8 jeweils die 4 nachfolgenden Zahlen.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 12.02.06 17:30 
user profile iconFlorian.K hat folgendes geschrieben:
Srry habe ich vergessen zu erwähnen. Ich gebe in mein Editfeld z.b 4 ein dann erscheint in meiner Listbox
5
6
7
8 jeweils die 4 nachfolgenden Zahlen.

Im Bezug auf dein erstes Posting bedeutet das, dass du die ganzen Zahlen addieren willst und dann z.B. bei der 4 im Edit1 dann als Erg 26 rauskommt (5+6+7+8) oder wie nun?

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Florian.K Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 12.02.06 17:42 
Die Zahlen in der Listbox werden der Zahl im EditFeld aufaddiert und ausgegeben.
bsp. Eingabe 4
Listbox 5 6 7 8 Ergebnis ist = 30
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: So 12.02.06 17:46 
Na dann - ich versuch mal den Code zu zaubern 8)

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
var i,Zahl,E:Integer;
begin
Zahl:=StrToInt(edtEingabewert.text);
E:=0;
For i := 1 To 4 do
 begin
 E:=i+Zahl;
 sleep(100);
 Listbox.Items.Add(IntToStr(E));
 Listbox.Refresh;
end;

For i := 0 to listbox1.items.count-1 do
begin
  E:=E+strtoint(listbox1.items[listbox1.itemindex]);
end;
E:=E+strtoint(edit1.text);
showmessage('Das Ergebnis ist +'inttostr(E));

Ich hab keine Lust das zu testen. Mach du ma. Wenns nicht klappt, dann sag Bescheid :wink:

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Florian.K Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 130

Win Xp Prof. & SP 2
Delphi 10 Lite
BeitragVerfasst: So 12.02.06 18:35 
Ne er meckert bei der Showmessage =(
(List Index out of bounds(-1)
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: So 12.02.06 18:41 
es muss ja auch...
ausblenden Delphi-Quelltext
1:
2:
E:=E+strtoint(edit1.text);
showmessage('Das Ergebnis ist '+ inttostr(E));  // <= hier war der fehler!

heißen ;)


[edit]
so gehts:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
...
For i := 0 to listbox1.items.count-1 do
begin
  E:=E+strtoint(listbox1.items[listbox1.itemindex+1]);
...