Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. add numbers from a listbox

add numbers from a listbox

Scheduled Pinned Locked Moved Visual Basic
csharp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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

    P 3 Replies Last reply
    0
    • L Lost User

      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

      P Offline
      P Offline
      Paul Riley
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • L Lost User

        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

        P Offline
        P Offline
        Paul Riley
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • L Lost User

          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

          P Offline
          P Offline
          Paul Riley
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups