Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 31st, 2008, 08:04 AM
mbristow mbristow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 2 mbristow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 30 sec
Reputation Power: 0
New to Programming

Hey guys and gals,
I'm pretty new to programming (and here actully, first post), I've began programming Delphi as my first real language as it is my college course chosen language (sucks). Anyway, heres my noobish question.

Is there a way to add items in a ListBox together... so in my list box i've got these peices of data:

1
2
3
4
5

Is there a way to add them all, so 1+2+3+4+5? Any help is apreciated, thanks again.

Matt.

Reply With Quote
  #2  
Old April 1st, 2008, 12:03 PM
clivew clivew is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 760 clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level)clivew User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 23 h 28 m 9 sec
Reputation Power: 19
Code:
function TForm1.ListTotal: Integer;
var
 i: integer;
begin
   Result := 0;
   for i := 0 to Listbox.Count-1 do begin
      Result := Result + strToInt(Listbox.Items[i]);
   end;
end;


Of course, in the real world you would want to do some checks to make sure the items in the listbox were actually integers.

Clive

Reply With Quote
  #3  
Old April 1st, 2008, 02:00 PM
mbristow mbristow is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 2 mbristow User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 43 m 30 sec
Reputation Power: 0
Thanks alot for the help, for our project its not needed to check if they were integers, instead only VALID data could be entered, so the check hasnt been implemented as of yet.

Thanks for the help, its been really helpful, i'll be sure to add devshed to the credits of the project.

I'm sure you will see me asking for help again sometime soon.

Thanks again Clive.

Matt.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > New to Programming


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway