Results 1 to 5 of 5

Thread: Get Sum Total of Column in Listview

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111

    Get Sum Total of Column in Listview

    I need to get Sum total of numeric data in in column



    Private Sub cmdLoad_Click()
    Dim itm As ListItem
    Itemcount = lv.ListItems.Count
    Dim a As String, b As String, C As String
    Open App.Path & "\Converted.txt" For Input As #1
    Do Until EOF(1)
    Input #1, a, b, C
    Set itm = lv.ListItems.Add(, , a)
    itm.SubItems(1) = b
    itm.SubItems(2) = C
    ' should I place code here and what code?
    Loop


    Close #1
    ' or here maybe a For loop to loop through though I am not
    ' sure just how to write the loop
    ' I was thinking something like
    ItemCount = lv.Listitems.Count
    For i = 1 to ItemCount
    ' some code here not sure what
    Next i
    End Sub


    Need Help on this one

    vbMarkO
    Last edited by vbMarkO; Feb 7th, 2004 at 02:01 PM.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629
    Either works, but I'd suggest you do the totals after making changes/updates to the listview through a called function.

    That way, you can create a reusable function which has as parameters; listview object, column number. You can even pass a range to the function if you want to say total of items 10-15. Then the function returns the total.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111
    Originally posted by leinad31
    Either works, but I'd suggest you do the totals after making changes/updates to the listview through a called function.

    That way, you can create a reusable function which has as parameters; listview object, column number. You can even pass a range to the function if you want to say total of items 10-15. Then the function returns the total.

    Yes that sounds like something I will definately use on another Listview in another section of my App... but this one simply needs to give the Sum Total of the Subitems(1) column

    Any idea what the code is for this?

    vbMarkO

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    VB Code:
    1. Dim lngIndex As Long
    2.     Dim lngTot As Long
    3.    
    4.     For lngIndex = 1 To lv.ListItems.Count
    5.         lngTot = lngTot + lv.ListItems(lngIndex).SubItems(1)
    6.     Next
    7.    
    8.     MsgBox lngTot

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    111
    Originally posted by MartinLiss
    VB Code:
    1. Dim lngIndex As Long
    2.     Dim lngTot As Long
    3.    
    4.     For lngIndex = 1 To lv.ListItems.Count
    5.         lngTot = lngTot + lv.ListItems(lngIndex).SubItems(1)
    6.     Next
    7.    
    8.     MsgBox lngTot
    Yes this works great... I also found that placing code in the Do Until loop works as well.

    such as

    iSubTotal = iSubTotal + Val(b)
    lblConv.Caption = iSubTotal
    Thank you I am going to use the For loop it will come in handy for other operations in my app.

    Now to find my next hill to climb..

    I am trying to find a way to Change the name of the first column when a user Clicks new date on DTPicker (known in my app as DTP)

    I can at Formload name it well actually it adds it but I need while running user clicks new Date it puts in the Columnheader title the results of Format(DTP.Value, "MMMM, yyyy") when DTP date is selected by user

    ie March 2004 or April 2004

    thanx again off to my searches

    vbMarkO

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