Results 1 to 12 of 12

Thread: [RESOLVED] How to sum this value?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Resolved [RESOLVED] How to sum this value?

    I used listview.. How to get the total value for each columnheader?
    Attached Images Attached Images  

  2. #2

  3. #3
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: How to sum this value?

    If it's for each column wouldn't it be:

    Listview.SubItem(1) + Listview.SubItem(2) = Total_Sum
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  4. #4

  5. #5
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: How to sum this value?

    Quote Originally Posted by RhinoBull
    I wasn't presenting syntax - only logic that's behind it.
    I do take things literally sometimes and I know how easily I get confused
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  6. #6

  7. #7

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to sum this value?

    The number of records is not limit only two records, How to sum the first records untill and the end of the records as I don't know the number of records exist in the listview

  8. #8
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: How to sum this value?

    You'll have to loop through all columns and add each column's value to some variable. Then assign that total value to perhaps last column in your listview control.
    Code:
    Private Sub Command1_Click()
    Dim itm As MSComctlLib.ListItem
    Dim subtotal As Single
    Dim i As Integer
    
        For Each itm In ListView1.ListItems
            subtotal = Val(itm.Text) '<<< comment this if you don't need to calculate value of the item itself
            For i = 1 To itm.ListSubItems.Count - 1
                subtotal = subtotal + Val(itm.ListSubItems(i).Text)
            Next i
            itm.ListSubItems(itm.ListSubItems.Count).Text = susbtotal
            subtotal = 0
        Next itm
    
    End Sub

  9. #9

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to sum this value?

    What the used of this code ?
    Only certain column I want to sum the value. I would like to sum each listitems for column1 and column 2
    Code:
    Private Sub Command1_Click()
    Dim itm As MSComctlLib.ListItem
    Dim subtotal As Single
    Dim i As Integer
    
        For Each itm In ListView1.ListItems
            subtotal = Val(itm.Text) '<<< comment this if you don't need to calculate value of the item itself
            For i = 1 To itm.ListSubItems.Count - 1
                subtotal = subtotal + Val(itm.ListSubItems(i).Text)
            Next i
            itm.ListSubItems(itm.ListSubItems.Count).Text = susbtotal
            subtotal = 0
        Next itm
    
    End Sub

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: How to sum this value?

    In one of my projects, I need to do two columns. Here is my code for that
    Code:
    For i = 1 To lvwIssues.ListItems.Count
        'estimated impact amount
        glngEstImpAmt = glngEstImpAmt + Val(lvwIssues.ListItems(i).SubItems(3))
        'acutal impact amount
        glngActImpAmt = glngActImpAmt + Val(lvwIssues.ListItems(i).SubItems(4))
        'Debug.Print lvwIssues.ListItems(i).SubItems(4)
    Next

  11. #11
    Frenzied Member aikidokid's Avatar
    Join Date
    Aug 2002
    Location
    Bristol, UK
    Posts
    1,968

    Re: How to sum this value?

    matrik02,

    Take a look at this quick example. You should be able to work this into your project
    Attached Files Attached Files
    If somebody helps you, take time to RATE the post. I do.

    "FAILURE IS NOT AN OPTION. It comes bundled with the software."

    Below are some of the threads that have helped me along the way:

    CodeBank submission:
    Listview Backcolor (without subclassing)

    Loading Treeview Nodes From A Database, Creating Registry Keys, Count Number of Lines in TextBox , Excellent RichTextBox Tricks & Tips
    Ideas & Screen Shots For A Code Library App
    How to do Data validation in Excel, Conditional Formating in Excel

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: [RESOLVED] How to sum this value?

    Thank you, that great 1

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