Results 1 to 13 of 13

Thread: Add listview subitems up and give total?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Add listview subitems up and give total?

    Hi guys, I have numbers in a listview sub item.

    Is it possible that on command1_click that it adds everything up and gives the total?

    For example I have

    1
    2
    8
    2

    is it possible to than make a label give the total as 13

    thanks

  2. #2
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Add listview subitems up and give total?

    Something like (not tested):

    Code:
    Dim iItem As ListItem
    Dim lngCount as long
     For Each iItem In YourListView.ListItems
         lngCount = lngCount + CLng(iItem.SubItems(PisitionOfYourSubItem))
     Next
    
    For example subitem is number 5
    
     For Each iItem In YourListView.ListItems
         lngCount = lngCount + CLng(iItem.SubItems(5))
     Next

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add listview subitems up and give total?

    Hi mate, that works how ever im adding up prices of products.

    Is it possible to format it to

    230,521

    as apose to 230521

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add listview subitems up and give total?

    Actually just noticed it is giving the incorrect total.

    on one listview the total comes to 88,000

    how ever it's giving the total with your code as 176,000

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Add listview subitems up and give total?

    I gave you two different examples. Just run one of them.

    Look up Format to add the commas.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add listview subitems up and give total?

    Oh right I see!

    I am now trying to add up times to create the total time spent.

    00:01:32
    00:03:58

    Should total up to 00:05:00

    how ever it just shows 0.

    Any ideas pal ?

  7. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Add listview subitems up and give total?

    Code:
    Dim MyTimeVar As Date
    
    'Do your Time additions
    
    MyTimeLabel.Caption=Format(MyTimeVar,"hh:mm:ss")
    Last edited by Zvoni; Sep 5th, 2012 at 08:50 AM.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add listview subitems up and give total?

    Hi Zvoni, That did not work as i am trying to total up the time, when i said it shows 0, i meant 00:00:00 as apose to actually totalling it up with the codes above.

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Add listview subitems up and give total?

    Can you post the relevant code where you're trying to add those time-values?
    Please include your Dim's

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2009
    Posts
    876

    Re: Add listview subitems up and give total?

    Dim iItem As ListItem
    Dim lngCount As Long

    Set rs = db.OpenRecordset("SELECT * FROM Calls WHERE `Agent` = " & "'" & ListView1.SelectedItem & "' AND `Date` BETWEEN " & "'" & DTPicker1.value & "' AND " & "'" & DTPicker2.value & "'")
    ListView2.ListItems.Clear
    Do While Not rs.EOF
    Set lvwItem1 = ListView2.ListItems.Add(, , rs("Length").value)



    rs.MoveNext
    Loop
    rs.Close


    For Each iItem In ListView2.ListItems
    lngCount = lngCount + CLng(iItem)
    Next

    time.Caption = Format(lngCount, "hh:mm:ss")

  11. #11
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Add listview subitems up and give total?

    Ah, there's your mistake.
    You've Dim-ed it as a Long instead of Date

    Question: What Datatype is "Length" in your Database?
    Code:
    Dim lngCount as Date
    .
    .
    For Each iItem In ListView2.ListItems
    lngCount = lngCount + CDate(iItem)
    Next
    
    time.Caption = Format(lngCount, "hh:mm:ss")

  12. #12
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Add listview subitems up and give total?

    It didn't come out until post #5 the OP is trying to add up time. That makes it a different ballgame. I can help in a few hours but that changes taking a date time column and figuring out total time form a listview

    Anyone?

  13. #13
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,268

    Re: Add listview subitems up and give total?

    *head scratch*

    I don't remember, but don't you have to use the DateAdd-Function when adding Date/Time-Values?

    Have to read up on it...

    EDIT: DateAdd is only for adding an interval to a given Date/Time
    Last edited by Zvoni; Sep 5th, 2012 at 10:16 AM.

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