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
Printable View
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
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
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
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
I gave you two different examples. Just run one of them. :bigyello:
Look up Format to add the commas.
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 ?
Code:Dim MyTimeVar As Date
'Do your Time additions
MyTimeLabel.Caption=Format(MyTimeVar,"hh:mm:ss")
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.
Can you post the relevant code where you're trying to add those time-values?
Please include your Dim's
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")
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")
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 :rolleyes:
Anyone?
*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