counting each repeated Items in Listview using vb6
Hi, All I have large number of words in Listview and I want to count each repeated word and pt the result in a new listview for example
the new list view must be like table bellow
word frequency
go 100
the 300
they 400
.
.
.
..
and so on , Please can any help
you kind action really appreciated
Re: counting each repeated Items in Listview using vb6
Sounds like the hard way to do it. Unless you have one word per item
Re: counting each repeated Items in Listview using vb6
I'm using vb regex to find the occurences of each word in large text file , the thing is i want to find all word and put them in a listview, then listing the occurences for each word inside the listview .... can i find the occurences of each word before i put the words inside the listview ???if can plese help ... I have the code to find all word in large text file using vb regular expression (regex) can u follow it to me please ????
Re: counting each repeated Items in Listview using vb6
Break it down into steps. Show the code for this part:
Code:
find all word and put them in a listview
But, as I said. Re-think the output. Listview isn't the right control.
Hint: Use TWO ListBoxes. One can be SORTED, to get the listbox into alphabetical order (to count occurrences)
Re: counting each repeated Items in Listview using vb6
Yes, I'd also say the listview is a bit overdone, but the usual ListBox as proposed by David might come to an end of available items, when your text is large and contains more than 32767 words, which could be the case, if you put all the doubles into the list in the first place.
However, you could do a test for doubles BEFORE entering a word into the listbox, getting away with probably less than 32000 DIFFERENT words.
You could first scan the list items and see if the word is already there.
Let's assume lstWords is a ListBox with the words.
Code:
Private Function EnterNewWord(NewWord As String) As Integer
' function returns -1 if word exists or returns the current word count
Dim i%
For i = 0 To lstWords.ListCount - 1
If lstWords.List(i) = NewWord Then
EnterNewWord = -1
Exit Function
End If
Next
lstWords.AddItem NewWord
EnterNewWord = lstWords.ListCount
End Function
If you want to use a ListView, however, the addressing of the items looks a little different, but it will be basically the same.
It could be a little slow, however, when a higher word count is reached.
A little faster could be this method:
Code:
Private AllWords As String
Private Function EnterNewWord(NewWord As String) As Integer
If InStr(AllWords, "|"+NewWord + "|") Then
EnterNewWord = -1
Else
AllWords = AllWords + NewWord + "|"
lstWords.AddItem NewWord
EnterNewWord = lstWords.Count
End If
End Function
It keeps a variable named AllWords, in which all new words are stored, too, although separated by a "|". This allows us to use the InStr() function to test if the word is already there as such.
If we wouldn't have the separator, the InStr() would fail. If a word like "automobile" is in the string, then the word "auto" is already there, too. The separator, however, allows to seek the word "|auto|", which cannot be mixed up.
You have to initialise the AllWords varibale like this, before doing a new document:
AllWords = "|"
so it starts with a separator for the first word.
Re: counting each repeated Items in Listview using vb6
Re: counting each repeated Items in Listview using vb6
Batches of 32K items AT A TIME... Or, use a database. No limits there
Re: counting each repeated Items in Listview using vb6
Re: counting each repeated Items in Listview using vb6
Using a DB would let you create a DICTIONARY of words, and then, use a query to modify (or just report) the FREQUENCY.
Even the other way, 32K words, with 100 top words. 10,000 top words. Sort and count them...
DB would be preferred
Re: counting each repeated Items in Listview using vb6
Yes you could read all the words from the file, insert each word into a database then run a query to get each word and the count of each word fairly easy using the count() and Group by SQL methods.
.
Re: counting each repeated Items in Listview using vb6
.............................
Re: counting each repeated Items in Listview using vb6
Fix your code tag so the code is readable the end tag needs to have a / rather than \
Re: counting each repeated Items in Listview using vb6
COPY List1 to List2, then COUNT the item(s) and eliminate the DUPLICATES. This will be your good list. Store the results back in List1, along with the COUNT appended
Code:
' append count to listbox
You saw code for that
Re: counting each repeated Items in Listview using vb6
.........................
Re: counting each repeated Items in Listview using vb6
Follow DataMiser's advice. You can download the program that I used in my article, here