Adding the numeric values in a combobox ?

if my combobox has 5 entries all numeric  eg:

1500
2000
25
50
1230

how can I add these values to give me a total (integer) ?

I have this code but it only gives me the value of the last entry in the combobox.....

for i := 0 to combobox2.items.count -1 do
begin

s := combobox2.itemindex + 1;
Combobox2.itemindex := ( s );
total := Strtoint(combobox2.items[combobox2.itemindex]);
label8.caption := Inttostr(total);
inc ( s );


As you can see here, label8.caption gets changed for each item in the combobox instead of adding them all up.  any help would be appreciated

thanks

Mark
LVL 20
Mark BradyPrincipal Data EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SlaughCommented:
label8.Caption := 0;
for i := 0 to combobox2.items.count -1 do
 begin
  combobox2.ItemIndex := i;
  label8.caption := inttostr(strtoint(label8.caption) + strtoint(combobox2.items[combobox2.itemindex]));
 end;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SlaughCommented:
ack, that first line should read: label8.Caption := '0';
0
Slick812Commented:
procedure TForm1.sbut_AddComboClick(Sender: TObject);
var
i, total: Integer;
begin
Total := 0;
for i := 0 to combobox1.items.count -1 do
begin
total := total+Strtoint(combobox1.items[i]);
end;
label3.caption := Inttostr(total);
end;
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Mark BradyPrincipal Data EngineerAuthor Commented:
Thanks slaugh !   Perfect answer.

Mark
0
SlaughCommented:
Just noticed that it can be shortened to:

label8.Caption := '0';
for i := 0 to combobox2.items.count -1 do
 label8.caption := inttostr(strtoint(label8.caption) + strtoint(combobox2.items[i]));
0
Mark BradyPrincipal Data EngineerAuthor Commented:
Good observation !  Thanks

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.