-
Oct 31st, 2018, 05:28 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Count unique numbers in a listview column?
Hello experts
I need to to count unique numbers in a listview column.
In other words it is like we substitute by Group By when dealing with database.
So I have a column like that:
10
20
10
30
30
10
40
20
So I have:
10 - 20 - 30 and 40
I want to get occurance = 4
thank you
Last edited by Mustaphi; Oct 31st, 2018 at 07:13 AM.
-
Oct 31st, 2018, 06:20 AM
#2
Re: Count some occurances in a listview column?
Use a collection with
Code:
On Error Resume Next
For i=1 to ListViewRowCount
MyCollection.Add ListViewValue, ListViewValue 'Note: Adding ListViewValue as the Value for the Collection-Item but also as the Key to the Item
Next
On Error Goto 0
Debug.Print MyCollection.Count
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
-
Oct 31st, 2018, 06:32 AM
#3
Thread Starter
Fanatic Member
Re: Count some occurances in a listview column?
Thanks sir
I'm getting Objet required here
Code:
Debug.Print MyCollection.Count
-
Oct 31st, 2018, 06:43 AM
#4
Thread Starter
Fanatic Member
Re: Count some occurances in a listview column?
this how I'm doing
Code:
For i = 1 To ListView1.ListItems.Count
MyCollection.Add ListView1.ListItems(i).SubItems(1), ListView1.ListItems(i).SubItems(1) 'Note: Adding ListViewValue as the Value for the Collection-Item but also as the Key to the Item
Next
On Error GoTo 0
Debug.Print MyCollection.Count
Last edited by Mustaphi; Oct 31st, 2018 at 09:31 AM.
-
Oct 31st, 2018, 06:47 AM
#5
Re: Count some occurances in a listview column?
Did you declare MyCollection? My guess is that the .Add is also throwing an error but the resume next is hiding it. All most likely because you didn't declare your variable.
-tg
-
Oct 31st, 2018, 06:53 AM
#6
Thread Starter
Fanatic Member
Re: Count some occurances in a listview column?
techgnome
thanks for your interest
Please can you telle me how should I declare it.
Code:
Dim MyCollection As String
didn't solve the issue
-
Oct 31st, 2018, 07:52 AM
#7
Re: Count some occurances in a listview column?
Originally Posted by Mustaphi
techgnome
thanks for your interest
Please can you telle me how should I declare it.
Code:
Dim MyCollection As String
didn't solve the issue
Originally Posted by Zvoni
Use a collection
-tg
-
Oct 31st, 2018, 08:08 AM
#8
Thread Starter
Fanatic Member
Re: Count unique numbers in a listview column?
techgnome
would provide some help please because no idea about using collection
-
Oct 31st, 2018, 08:26 AM
#9
Re: Count unique numbers in a listview column?
If you don't what know collections are then better read the help first.
Press F1 and search for "collections"
-
Oct 31st, 2018, 08:34 AM
#10
Thread Starter
Fanatic Member
Re: Count unique numbers in a listview column?
Originally Posted by Arnoutdv
If you don't what know collections are then better read the help first.
Press F1 and search for "collections"
I already declared it as collection but did not work
Code:
Dim MyCollection As Collection
-
Oct 31st, 2018, 08:53 AM
#11
Re: Count unique numbers in a listview column?
Right... this isn't your first trip to the rodeo... think about it... it's a collection object. You can't use an object until you create it... how do you create a new instance of an object? Again... how do you create a NEW instance of an object.... think about it... a NEW object... hint hint hint....
-tg
ps - yes, I'm making you use your brain here....
-
Oct 31st, 2018, 09:37 AM
#12
Thread Starter
Fanatic Member
Re: Count unique numbers in a listview column?
Code:
Dim MyCollection As Collection
Set MyCollection = New Collection
For i = 1 To ListView1.ListItems.Count
MyCollection.Add ListView1.ListItems(i).SubItems(1), ListView1.ListItems(i).SubItems(1) 'Note: Adding ListViewValue as the Value for the Collection-Item but also as the Key to the ItemNext
Next
On Error GoTo 0
Debug.Print MyCollection.Count
Error
the key is already associated with an element of the collection
-
Oct 31st, 2018, 09:39 AM
#13
Re: Count unique numbers in a listview column?
Where is the "On Error Resume Next"?
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
-
Oct 31st, 2018, 10:26 AM
#14
Thread Starter
Fanatic Member
Re: Count unique numbers in a listview column?
Zvoni
thank you very much
solved
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
|