Listbox

0b15bc9413d8991c33da3d3f1fbc748e
0
Dips 101 Apr 18, 2007 at 09:23

I have some figures in a listbox and would like all the values to be added together. Any one how i would go about that?

9 Replies

Please log in or register to post a reply.

A9102969e779768e6f0b8cb87e864c94
0
dave_ 101 Apr 18, 2007 at 09:34

No. The question is too vague.
What language/api are you using?
It’s probably very easy to do, and it shows that you don’t really understand how to program.
Perhaps you should look at some programming tutorials. If you’re using C/C++ look up for/while loops.

int total = 0
for each item in listbox
  total = total + atoi(item.value) // atoi to convert from string to integer
0b15bc9413d8991c33da3d3f1fbc748e
0
Dips 101 Apr 18, 2007 at 09:37

sorry i am using using vishual studio 2005

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Apr 18, 2007 at 09:43

That doesn’t help anything. First of all, Visual Studio represents a whole suite of different languages (C++, C#, VB.Net, …). Secondly, you don’t describe the problem at hand. What is your exact problem? Give us a detailed description and show us the code you already have. What results are you getting from that code? And what are you expecting to get?

If you can’t answer these questions we can’t help you. If you’re just looking for someone to implement it for you you have come to the wrong place.

A9102969e779768e6f0b8cb87e864c94
0
dave_ 101 Apr 18, 2007 at 09:43

Last time I looked, visual studio supported C++, C#, J# and visual basic.

Sounds like you can’t program at all. I’m afraid you’re asking the wrong questions if you want to learn how to program.

0b15bc9413d8991c33da3d3f1fbc748e
0
Dips 101 Apr 18, 2007 at 09:46

i am using visual studio, vishual basic 2005. I am trying to get values from a listbox which are figures and add them together. I no i am new to this and am doing this as part of a school project. Thank you

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Apr 18, 2007 at 09:47

I am trying to get values from a listbox which are figures and add them together

Show us your sourcecode. And of course only the relevant part, e.g., the function that needs to add the elements of the listbox together.

0b15bc9413d8991c33da3d3f1fbc748e
0
Dips 101 Apr 18, 2007 at 09:49

this is the code i am using to populate my listbox

If com1.Text = “Bond Street” Then
objConnection.Open()
Dim strSql As String = “SELECT * from Feedback WHERE Attractionname = ‘Bond Street’” Dim objCommand As New System.Data.OleDb.OleDbCommand(strSql, objConnection)
Dim objReader As System.Data.OleDb.OleDbDataReader
objReader = objCommand.ExecuteReader
If objReader.HasRows Then
While objReader.Read
ListBox1.Items.Add(objReader.GetValue(2))
ListBox2.Items.Add(objReader.GetValue(3))
End While
End If

the items in listbox2 are all figures and i want them to be added together

340bf64ac6abda6e40f7e860279823cb
0
_oisyn 101 Apr 18, 2007 at 09:54

Please put your code in [code**]…[/code] blocks :)

You can iterate over the items in the list with

For Each item as Object in ListBox2.Items
    ' what is the type of an item? You should convert it to a numerical type (such as Integer or Single) and add them to a variable.
End For
0b15bc9413d8991c33da3d3f1fbc748e
0
Dips 101 Apr 18, 2007 at 09:58

Dont worry about it now im sure il find a way. Thanks