-
November 2nd, 2011, 06:18 AM
#16
Re: counting each repeated Items in Listview using vb6
...................................
Last edited by falahjomor; December 4th, 2011 at 12:35 PM.
-
November 12th, 2011, 02:45 PM
#17
Re: counting each repeated Items in Listview using vb6
.................................
Last edited by falahjomor; December 4th, 2011 at 12:37 PM.
-
November 12th, 2011, 02:47 PM
#18
Re: counting each repeated Items in Listview using vb6
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.
Always use [code][/code] tags when posting code.
-
November 12th, 2011, 02:50 PM
#19
Re: counting each repeated Items in Listview using vb6
.........................................
Last edited by falahjomor; December 4th, 2011 at 12:36 PM.
-
November 12th, 2011, 02:55 PM
#20
Re: counting each repeated Items in Listview using vb6
All the words you should need are provided in my previous post, try a few combinations and see what you get.
Always use [code][/code] tags when posting code.
-
December 9th, 2011, 05:25 PM
#21
Re: counting each repeated Items in Listview using vb6
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
-
December 9th, 2011, 10:24 PM
#22
Re: counting each repeated Items in Listview using vb6
Originally Posted by DinoVaught
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
thank you for the nice code, but i tried your code with textfile of 64000 words and show me an error "error occurred getsubmatches Overflow"
Best Regard
-
December 9th, 2011, 11:38 PM
#23
Re: counting each repeated Items in Listview using vb6
Why have you deleted content from earlier posts?
Always use [code][/code] tags when posting code.
-
December 12th, 2011, 12:58 PM
#24
Re: counting each repeated Items in Listview using vb6
Originally Posted by falahjomor
thank you for the nice code, but i tried your code with textfile of 64000 words and show me an error "error occurred getsubmatches Overflow"
Best Regard
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.
-
December 12th, 2011, 01:41 PM
#25
Re: counting each repeated Items in Listview using vb6
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.
Always use [code][/code] tags when posting code.
-
December 15th, 2011, 02:39 PM
#26
Re: counting each repeated Items in Listview using vb6
-
December 15th, 2011, 08:15 PM
#27
Re: counting each repeated Items in Listview using vb6
Originally Posted by WoF
????
Spam, close to absolute certainty. Try a search for posts from this "user" for confirmation...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
-
December 15th, 2011, 10:57 PM
#28
Re: counting each repeated Items in Listview using vb6
-
December 16th, 2011, 06:22 PM
#29
Re: counting each repeated Items in Listview using vb6
Ok. The weird post is gone and my question marks remain.
You know, they weren't meant to follow your post, DataMiser...
-
December 16th, 2011, 07:20 PM
#30
Re: counting each repeated Items in Listview using vb6
does look a little odd now but I did see the other post before it was removed.
Always use [code][/code] tags when posting code.
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
|