-
Aug 15th, 2022, 08:37 AM
#1
Thread Starter
Junior Member
[RESOLVED] please help; how to sum duplicate listview sub item
i have listview with data like this,
Name Total
Jon 10
Joe 15
Trump 5
Sarah 7
Gina 16
Jon 5
Joe 5
Sarah 10
Biden 9
i want sum duplicate total like this to my form preview,
Name Total
Jon 15
Joe 20
Trump 5
Sarah 17
Gina 16
Sarah 10
Biden 9
Code:
frmPreview.Print Tab(3); "Name";
frmPreview.Print Tab(15); "Total";
please help me thanks
-
Aug 15th, 2022, 08:46 AM
#2
Re: please help; how to sum duplicate listview sub item
Sam I am (as well as Confused at times).
-
Aug 15th, 2022, 08:54 AM
#3
Thread Starter
Junior Member
Re: please help; how to sum duplicate listview sub item
@SamOscarBrown yes still need to learn a lot from the masters
-
Aug 15th, 2022, 09:19 AM
#4
Re: please help; how to sum duplicate listview sub item
Thought so....but, tell ya what...post what YOU have tried first. Just think of it in terms of iterating through the first column, and find duplicates. When you find them, you should be able to 'see' the value in the second column and save it to a variable (an array might be of benefit, but probably you're not into arrays yet.
Sam I am (as well as Confused at times).
-
Aug 15th, 2022, 03:16 PM
#5
Hyperactive Member
Re: please help; how to sum duplicate listview sub item
What data structures are you currently studying? Arrays, database tables, collection, dictionary? There's an answer for each type. If your data structure is a table, then I would start with learning how to do a SUM group by query.
-
Aug 16th, 2022, 01:20 AM
#6
Thread Starter
Junior Member
Re: please help; how to sum duplicate listview sub item
@ahenry @SamOscarBrown ok i am using access database and using command button to search my data from db to showing in my listvie and then my form1 have rightclick menu to view data as report
Code:
Private Sub cmdSearch_Click()
Dim k As ListItem
Form1.lvMain.ListItems.Clear
myRecordset "Select * FROM QMain WHERE cdate(Format$(Tanggal, ""dd/mm/yyyy"")) BETWEEN #" & Format(DTPicker1.Value, "mm/dd/yyyy") & "# AND #" & Format(DTPicker2.Value, "mm/dd/yyyy") & "# ORDER BY ID;"
While Not myrs.EOF = True
Set k = Form1.lvMain.ListItems.Add(, , Format(myrs.Fields("Tanggal"), "DD/MM/YYYY"))
k.SubItems(1) = myrs.Fields("NoPlat")
k.SubItems(2) = myrs.Fields("Supir")
k.SubItems(3) = myrs.Fields("Kenek")
k.SubItems(4) = myrs.Fields("ritSupir")
k.SubItems(5) = myrs.Fields("ritKenek")
myrs.MoveNext
Wend
End Sub
i want to showing report from my listview data after searching my db using rightclickmenu
Code:
Private Sub mnuDailyPreview_Click()
frmPreview.Show
CdailyView
End Sub
Code:
Private Sub CdailyView()
frmPreview.Move 3800, 2000
frmPreview.Width = 14800
frmPreview.Height = 10000
frmPreview.Print
frmPreview.FontBold = True
frmPreview.FontSize = 10
frmPreview.FontName = "Courier New"
frmPreview.Print Tab(3); "Daily report"
grs = String$(100, "-")
frmPreview.FontBold = False
frmPreview.FontSize = 9
frmPreview.Print Tab(3); grs;
frmPreview.Print Tab(3); "Tanggal";
frmPreview.Print Tab(15); "No Pelat";
frmPreview.Print Tab(27); "Supir";
frmPreview.Print Tab(37); "Kenek";
frmPreview.Print Tab(57); "ritSup";
frmPreview.Print Tab(77); "ritKnk";
frmPreview.Print Tab(3); grs;
End If
Dim i As Long
With frmMain.lvMain
For i = 1 To frmMain.lvMain.ListItems.Count
frmPreview.Print Tab(3); frmMain.lvMain.ListItems(i);
frmPreview.Print Tab(15); frmMain.lvMain.ListItems(i).ListSubItems(1);
frmPreview.Print Tab(27); frmMain.lvMain.ListItems(i).ListSubItems(2);
frmPreview.Print Tab(37); frmMain.lvMain.ListItems(i).ListSubItems(3);
frmPreview.Print Tab(57); frmMain.lvMain.ListItems(i).ListSubItems(4);
frmPreview.Print Tab(77); frmMain.lvMain.ListItems(i).ListSubItems(5);
Next i
End With
grsT = String$(100, "=")
frmPreview.Print Tab(3); grsT;
frmPreview.Print Tab(3); ' i want show Sum duplicate item from my listview like this
Supir Total Kenek Total
=================================
Jon 15 Robert 50
Joe 20 Jose 25
Trump 5 Tina 15
Sarah 17
Gina 16
Sarah 10
Biden 9
------------------------------------------------------------------
Grant Total 92 90
End Sub
like that i want to do ....
-
Aug 16th, 2022, 01:26 AM
#7
Re: please help; how to sum duplicate listview sub item
Originally Posted by joelin
@SamOscarBrown yes still need to learn a lot from the masters
Yeah, right......
Homework.....
Joined in 2009 (13 years ago), at age what? 4 years old?
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Aug 16th, 2022, 01:37 AM
#8
Thread Starter
Junior Member
Re: please help; how to sum duplicate listview sub item
Originally Posted by Zvoni
Yeah, right......
Homework.....
Joined in 2009 (13 years ago), at age what? 4 years old?
joining date is not guaranteed lol sometimes forget because i haven't used it for a long time
-
Aug 16th, 2022, 05:53 AM
#9
Thread Starter
Junior Member
Re: please help; how to sum duplicate listview sub item
ok i have found the answer
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
|