Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox Totals

Status
Not open for further replies.

dredfern

Technical User
Dec 7, 2003
14
GB
Is it possible to get the total of a list of numbers in a ListBox and then update the total as new numbers are added?
 
Yes, but you would need to calculate the entire total as you go. Something like this should do it.

Code:
var
  X,MyNumber,MyTotal : Integer;
begin
  if ListBox1.Items.Count > 0 then
  begin
    X := 0;
    MyTotal := 0;
    repeat
      MyNumber := StrToInt(ListBox1.Strings[X]);
      MyTotal := MyTotal + MyNumber;
      X := X + 1;
    until X = ListBox1.Items.Count;
  end;
end;


When your feeling down and your resistance is low, light another cigarette and let yourself go [rockband]
 
Eric, Thanks a lot for that. I'll give it a try.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top