?
Solved

Adding the numeric values in a combobox ?

Posted on 2003-02-22
6
Medium Priority
?
253 Views
Last Modified: 2010-04-04
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
0
Comment
Question by:Mark Brady
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
Slaugh earned 200 total points
ID: 8001643
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
 
LVL 1

Expert Comment

by:Slaugh
ID: 8001651
ack, that first line should read: label8.Caption := '0';
0
 
LVL 34

Expert Comment

by:Slick812
ID: 8001658
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 20

Author Comment

by:Mark Brady
ID: 8006669
Thanks slaugh !   Perfect answer.

Mark
0
 
LVL 1

Expert Comment

by:Slaugh
ID: 8006690
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
 
LVL 20

Author Comment

by:Mark Brady
ID: 8009842
Good observation !  Thanks

0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month9 days, 9 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question