...................................
Printable View
...................................
.................................
You use SQL Insert statements to insert the data.
You use a SQL select with the Count() and Group by methods to get the results.
You can find lots of info and examples on these with a simple google search.
.........................................
All the words you should need are provided in my previous post, try a few combinations and see what you get.
Falahjomor,
I see a multiple questions from you regarding ways to count the frequency of words from a text file. I have an example below, it doesn't use the listview control that you ask about. It uses ListBox controls instead, I believe that it does give you word counts you're asking about though.
Code assumes a form with . .
A command button named "cmdCountWords"
A listbox named "lstAllWords"
A listbox named "lstWordCount"
Manually set Sorted property of both ListBox controls to True
Code:Option Explicit
Private Sub cmdCountWords_Click()
GetSubMatches
End Sub
Private Sub GetSubMatches()
Dim sFileContents As String
Dim saFileContents() As String
Dim iFreeFile As Integer
Dim iListCount As Long
Dim iWordCount As Long
Dim sCurrentWord As String
Dim sLastWord As String
On Error GoTo GetSubMatchesErrHandler
iFreeFile = FreeFile
Open "C:\Path\To\File.txt" For Binary As #iFreeFile
sFileContents = Input(LOF(iFreeFile), iFreeFile)
sFileContents = Replace(sFileContents, vbCr, " ")
sFileContents = Replace(sFileContents, vbLf, " ")
iListCount = 0
saFileContents = Split(sFileContents, " ")
Do Until iListCount > UBound(saFileContents)
If saFileContents(iListCount) = vbNullString Then
Else
Me.lstAllWords.AddItem saFileContents(iListCount)
End If
iListCount = iListCount + 1
Loop
iWordCount = 0
iListCount = 0
sCurrentWord = Me.lstAllWords.List(iListCount)
sLastWord = sCurrentWord
Do Until iListCount = Me.lstAllWords.ListCount
sCurrentWord = Me.lstAllWords.List(iListCount)
If UCase$(sCurrentWord) = UCase$(sLastWord) Then
iWordCount = iWordCount + 1
Else
Me.lstWordCount.AddItem sLastWord & " " & Format$(iWordCount + 1)
iWordCount = 0
sLastWord = sCurrentWord
End If
iListCount = iListCount + 1
Loop
GetSubMatchesExitPoint:
On Error Resume Next
Close #iFreeFile
Erase saFileContents
Exit Sub
GetSubMatchesErrHandler:
Select Case Err.Number
Case Else
MsgBox "Error occured in GetSubMatches" & vbCrLf & vbCrLf & Err.Description, vbOKOnly + vbExclamation
End Select
Resume GetSubMatchesExitPoint
End Sub
Why have you deleted content from earlier posts?
I was able to recreate the same error you mention.
Although you can load more than 32767 items into a listbox or treeview, as soon as you try to read them using List(###) and ### is more than 32767 the overflow error will fire.
These controls, listbox or treeview, have the limitations or maximum values of a signed integer which is 32767 in VB.
There are numerous ways around this. You'll just have to use something other than the listview or listbox. Considering the amount of data you're dealing with, as others have suggested, you may want to considering using a database
In the sample code I posted, the general idea is there. Each line of code that adds an item to a list box could replaced with in INSERT into a table in a database, massaged then queried back to your VB application and displayed by a control that can handle more than the 64000 words you mention.
Odds are that once they are placed into a database and a proper count query is executed the number of words returned will be far less than the number in the original document as words like The, and and other common words may occur lots of times but the query should return the word only once with the number of occurances. So 64k words could turn into 20k or even less depending on the content of the document in question.
????
Reported
Ok. The weird post is gone and my question marks remain.
You know, they weren't meant to follow your post, DataMiser...
:) does look a little odd now but I did see the other post before it was removed.