Results 1 to 12 of 12

Thread: [RESOLVED] How to sum this value?

Hybrid View

  1. #1

    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

  2. #2
    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

  3. #3

    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

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