|
-
Aug 29th, 2012, 08:41 AM
#1
Thread Starter
Fanatic Member
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
-
Aug 29th, 2012, 11:47 AM
#2
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
-
Aug 30th, 2012, 03:44 AM
#3
Thread Starter
Fanatic Member
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
-
Aug 30th, 2012, 04:02 AM
#4
Thread Starter
Fanatic Member
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
-
Aug 30th, 2012, 04:38 AM
#5
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.
-
Sep 5th, 2012, 08:29 AM
#6
Thread Starter
Fanatic Member
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 ?
-
Sep 5th, 2012, 08:43 AM
#7
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.
-
Sep 5th, 2012, 08:57 AM
#8
Thread Starter
Fanatic Member
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.
-
Sep 5th, 2012, 09:26 AM
#9
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
-
Sep 5th, 2012, 09:37 AM
#10
Thread Starter
Fanatic Member
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")
-
Sep 5th, 2012, 09:49 AM
#11
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")
-
Sep 5th, 2012, 10:02 AM
#12
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?
-
Sep 5th, 2012, 10:13 AM
#13
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|