|
-
Feb 7th, 2004, 01:58 PM
#1
Thread Starter
Lively Member
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.
-
Feb 7th, 2004, 02:42 PM
#2
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.
-
Feb 7th, 2004, 03:20 PM
#3
Thread Starter
Lively Member
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
-
Feb 7th, 2004, 03:29 PM
#4
VB Code:
Dim lngIndex As Long
Dim lngTot As Long
For lngIndex = 1 To lv.ListItems.Count
lngTot = lngTot + lv.ListItems(lngIndex).SubItems(1)
Next
MsgBox lngTot
-
Feb 7th, 2004, 07:38 PM
#5
Thread Starter
Lively Member
Originally posted by MartinLiss
VB Code:
Dim lngIndex As Long
Dim lngTot As Long
For lngIndex = 1 To lv.ListItems.Count
lngTot = lngTot + lv.ListItems(lngIndex).SubItems(1)
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|