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?
Listbox
Started by Dips, Apr 18 2007 09:23 AM
9 replies to this topic
#1
Posted 18 April 2007 - 09:23 AM
#2
Posted 18 April 2007 - 09:34 AM
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.
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
#3
Posted 18 April 2007 - 09:37 AM
sorry i am using using vishual studio 2005
#4
Posted 18 April 2007 - 09:43 AM
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.
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.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#5
Posted 18 April 2007 - 09:43 AM
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.
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.
#6
Posted 18 April 2007 - 09:46 AM
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
#7
Posted 18 April 2007 - 09:47 AM
Quote
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.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#8
Posted 18 April 2007 - 09:49 AM
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
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
#9
Posted 18 April 2007 - 09:54 AM
Please put your code in [code]...[/code] blocks 
You can iterate over the items in the list with
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
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.
-
Currently working on: the 3D engine for Tomb Raider.
#10
Posted 18 April 2007 - 09:58 AM
Dont worry about it now im sure il find a way. Thanks
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











