473,409 Members | 1,970 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,409 software developers and data experts.

Listbox SelectedItem addition

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 2366
manch
2
Here is what i have so far...

Expand|Select|Wrap|Line Numbers
  1.  intTnum = lstNum.Items.Count
  2.  
  3.         For intX = 0 To intTnum
  4.             intTLoop = lstNum.Items(0)
  5.             intTSum = intTSum + intTLoop
  6.             intX += 1
  7.         Next intX
How can i increment lstNum.Items(0) to the next number with each repetition of the loop?
May 14 '07 #2
danp129
323 Expert 256MB
Didn't test but this should work:
Expand|Select|Wrap|Line Numbers
  1. For intX = 0 To lstNum.Items.Count
  2.     intTLoop = lstNum.Items(intX)
  3.     intTSum = intTSum + intTLoop
  4. Next 'intX this is optional
May 14 '07 #3
Killer42
8,435 Expert 8TB
Here is what i have so far...

Expand|Select|Wrap|Line Numbers
  1.  intTnum = lstNum.Items.Count
  2.  
  3.         For intX = 0 To intTnum
  4.             intTLoop = lstNum.Items(0)
  5.             intTSum = intTSum + intTLoop
  6.             intX += 1
  7.         Next intX
...
You're actually very close. Just two problems jump out at me...
  1. lstNum.Items(0) should be lstNum.Items(intX)
  2. 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
Killer42
8,435 Expert 8TB
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

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: mathieu cupryk | last post by:
I have problems with listboxes in the webform2.cs, the textboxes are working well when I do a click on next. I am missing something. It works with the textboxes. Here is the file: using System;...
2
by: David Ichilov | last post by:
I've class derived from "Object" class, with ToString() method overriden itc. , now i add object of this class to Windows.Forms.ListBox.Items collection, and it works fine, displaying what...
3
by: John S | last post by:
How can you 1.) Get the text of an item selected? 2.) Get the index number of the item selected? 3.) Tell if the user clicked in a blank area?
2
by: Allan Horwitz | last post by:
When I try to reference the lstproducts.selecteditem.value using autopostback from the lstproducts listbox I get an error? How can I fix my code to get the selected value from the lstproducts...
4
by: Moe Sizlak | last post by:
Hi There, I am trying to return the value of a listbox control that is included as a user control, I can return the name of the control but I can't access the integer value of the selected item,...
7
by: Ohad Asor | last post by:
Hello all, I have an ASP.NET page I've written using VS.NET2003, which have a ListBox in it. When I press a button in the form, I try to get the selected item in the list by calling...
6
by: Sparky Arbuckle | last post by:
The code below works to an extent. The problem with it is that no matter which item is selected, the first one in the list is always the item that gets added/removed. How can I alleviate this...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
3
by: thomasp | last post by:
Has anyone got some sample code to do drag and drop from one listbox to another listbox using VB.Net 2005. The below code works for draging and droping one at a time, but not for multiselected...
1
by: jasydnor | last post by:
Hi, New to the forums and have a question. I've only been developing for about five months now so I apologize if this seems oversimplistic....I am writing a program on an idea I had on a whim. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.