Results 1 to 4 of 4

Thread: [02/03] Total in a listbox

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    61

    [02/03] Total in a listbox

    I have 5 items in a listbox, and I want to have the total of those items saved to variable that I can use later?

    How do I add those items up to a variable?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Total in a listbox

    vb Code:
    1. Dim total As Integer = 0
    2.  
    3. For Each item As Integer In myListBox.Items
    4.     total += item
    5. Next item
    6.  
    7. MessageBox.Show("Total = " & total)
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2007
    Posts
    61

    Re: [02/03] Total in a listbox

    Ok say I have 5 numbers
    1
    4
    5
    3
    2

    I want 15 to be stored as a variable in the form so I can use it with a DIFFERENT event procedure?

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Total in a listbox

    I've already given you the solution.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width