434,786 Members | 1,142 Online
Need help? Post your question and get tips & solutions from a community of 434,786 IT Pros & Developers. It's quick & easy.

 P: 2 I need some help with this, just can't seem to get it straight. I need to write a loop that will add each item of a listbox to get a Sum of the numbers inside. I am using vb.net 2005 May 14 '07 #1
4 Replies

 P: 2 Here is what i have so far... Expand|Select|Wrap|Line Numbers  intTnum = lstNum.Items.Count           For intX = 0 To intTnum             intTLoop = lstNum.Items(0)             intTSum = intTSum + intTLoop             intX += 1         Next intX How can i increment lstNum.Items(0) to the next number with each repetition of the loop? May 14 '07 #2

 Expert 100+ P: 321 Didn't test but this should work: Expand|Select|Wrap|Line Numbers For intX = 0 To lstNum.Items.Count     intTLoop = lstNum.Items(intX)     intTSum = intTSum + intTLoop Next 'intX this is optional May 14 '07 #3

 Expert 5K+ P: 8,434 Here is what i have so far... Expand|Select|Wrap|Line Numbers  intTnum = lstNum.Items.Count           For intX = 0 To intTnum             intTLoop = lstNum.Items(0)             intTSum = intTSum + intTLoop             intX += 1         Next intX ... You're actually very close. Just two problems jump out at me...lstNum.Items(0) should be lstNum.Items(intX) The For loop automatically increments the counter (intX in this case). So by adding 1 to it again, you will be skipping every second item. May 15 '07 #4

 Expert 5K+ P: 8,434 I have a question about list box too if i may.. I'm going to split this question and my response to a new thread, just so they're easier for others to find. I'll come back and put a link here. ... Ok, it's How to sum a 'column' in a listbox holding tab-delimited text May 21 '07 #5