add numbers from a listbox
-
I am trying to add numbers from a listbox Its working with vb6 but not with vb.net. That's what I tried but it's not working Dim sum As Integer Dim i As Integer sum = 0 i = 0 For i = 0 To ListBox2.Items.Count - 1 sum = sum + ListBox2.Items(ListBox2.SelectedIndex) Next i TextBox5.Text = sum I would like the sum of what's inside the listbox to appear inside the textbox Ex: 12 + 12 + 12 from the listbox and sum would be 36 in the textbox
-
I am trying to add numbers from a listbox Its working with vb6 but not with vb.net. That's what I tried but it's not working Dim sum As Integer Dim i As Integer sum = 0 i = 0 For i = 0 To ListBox2.Items.Count - 1 sum = sum + ListBox2.Items(ListBox2.SelectedIndex) Next i TextBox5.Text = sum I would like the sum of what's inside the listbox to appear inside the textbox Ex: 12 + 12 + 12 from the listbox and sum would be 36 in the textbox
I'm thinking you might want to go for sum = sum + CInt(ListBox2.Items(ListBox2.SelectedIndex).Value) Paul Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
-
I am trying to add numbers from a listbox Its working with vb6 but not with vb.net. That's what I tried but it's not working Dim sum As Integer Dim i As Integer sum = 0 i = 0 For i = 0 To ListBox2.Items.Count - 1 sum = sum + ListBox2.Items(ListBox2.SelectedIndex) Next i TextBox5.Text = sum I would like the sum of what's inside the listbox to appear inside the textbox Ex: 12 + 12 + 12 from the listbox and sum would be 36 in the textbox
Please respond to forum Golfmaltais wrote: it's still makes a error sum = sum + CInt(ListBox2.Items(ListBox2.SelectedIndex).Value) public 'Value' type of 'DataRowView' is no where to be found. Ooops. My bad. What happens when you use For i = 0 To ListBox2.Items.Count - 1 sum = sum + ListBox2.Items(ListBox2.SelectedIndex) Next i ? Paul Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop
-
I am trying to add numbers from a listbox Its working with vb6 but not with vb.net. That's what I tried but it's not working Dim sum As Integer Dim i As Integer sum = 0 i = 0 For i = 0 To ListBox2.Items.Count - 1 sum = sum + ListBox2.Items(ListBox2.SelectedIndex) Next i TextBox5.Text = sum I would like the sum of what's inside the listbox to appear inside the textbox Ex: 12 + 12 + 12 from the listbox and sum would be 36 in the textbox
PLEASE respond to forum Golfmaltais wrote: not valid with type of 'Integer' and type of 'DataRowView' Hold on! I've only just clicked on to this DataRowView thing. How is ListBox2 defined? A ListBox item should be of type Object. A DataRowView is an item of a DataView. [edit]I have this question wrong. I should be asking "How is ListBox2 populated?"[/edit] Paul Why don't you take a good look at yourself and describe what you see - Led Zeppelin, Misty Mountain Hop