Link to home
Start Free TrialLog in
Avatar of rjef
rjefFlag for United States of America

asked on

sub total listview

I vb6 how would i total these values in a listview?  When po and item are equal and there is no serial value
 
POitemserialQtytag
11111
110
11111
110
1231XXXX1XX
1231XXY1XY
112111
15
112111
16
112111
10










OUTPUT



POITEMSERAIALQTYTAG
11111
220
1231XXXX1XX
1231XXY1XY
112111
41

Avatar of Martin Liss
Martin Liss
Flag of United States of America image

If you could attach a sample project it would save me some work.
Nevermind.
Did I do something similar to this for you a while back?
Add this code to a button on the form. Change line 11 to match the name of your listview and change line 58 to match the name of your command button.

Private Sub cmdSubtotal_Click()

Dim lngTotal As Long
Dim strOldPO As String
Dim strOldItem As String
Dim lngEntry As Long
Dim itmX As ListItem
Dim lngStart As Long
Dim lngDelete As Long

With lvSubTotal
    strOldPO = .ListItems(.ListItems.Count)
    strOldItem = .ListItems(.ListItems.Count).ListSubItems(1)
    lngStart = .ListItems.Count

    For lngEntry = .ListItems.Count To 1 Step -1
            If strOldPO = .ListItems(lngEntry) Then
                lngTotal = lngTotal + .ListItems(lngEntry).ListSubItems(3)
            Else
                ' Remove the detail entries...
                For lngDelete = lngStart To lngEntry + 1 Step -1
                    .ListItems.Remove lngDelete
                Next
                lngStart = .ListItems.Count
                
                ' ...and add a subtotal
                Set itmX = .ListItems.Add(, , strOldPO)
                itmX.SubItems(1) = strOldItem
                itmX.SubItems(2) = ""
                itmX.SubItems(3) = lngTotal
                itmX.SubItems(4) = ""
                
                Do Until .ListItems(lngEntry).ListSubItems(2) = ""
                    lngStart = lngStart - 1
                    lngEntry = lngEntry - 1
                Loop
                strOldPO = .ListItems(lngEntry)
                strOldItem = .ListItems(lngEntry).ListSubItems(1)
                lngTotal = 0
                ' This is needed because lngEnry is decremented when the loop starts over
                lngEntry = lngEntry + 1
            End If
'        End If
     Next
    ' Process the first PO
    For lngDelete = lngStart To lngEntry + 1 Step -1
        .ListItems.Remove lngDelete
    Next
    
    ' The 1 here pleces the new entty at the top of the list
    Set itmX = .ListItems.Add(1, , strOldPO)
    itmX.SubItems(1) = strOldItem
    itmX.SubItems(2) = ""
    itmX.SubItems(3) = lngTotal
    itmX.SubItems(4) = ""
End With

cmdSubTotal.Enabled = False

End Sub

Open in new window

Avatar of rjef

ASKER

sort of but i could not compare
TestSubtotals.zip
Avatar of rjef

ASKER

If the last row is
      

PO      item      serial      Qty      tag
113      111                             10      


it messes up
I don't understand. Try this.
29201550.zip
OK I attached my project before I saw your last post. I'll get back to you tomorrow.
Avatar of rjef

ASKER

thanks
Is the "10" in that last row a Tag or is it a Qty?
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Does my new code work for you?