CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 30 of 30
  1. #16
    Join Date
    Oct 2011
    Location
    Malaysia , Selangor
    Posts
    89

    Re: counting each repeated Items in Listview using vb6

    ...................................
    Last edited by falahjomor; December 4th, 2011 at 12:35 PM.

  2. #17
    Join Date
    Oct 2011
    Location
    Malaysia , Selangor
    Posts
    89

    Re: counting each repeated Items in Listview using vb6

    .................................
    Last edited by falahjomor; December 4th, 2011 at 12:37 PM.

  3. #18
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  4. #19
    Join Date
    Oct 2011
    Location
    Malaysia , Selangor
    Posts
    89

    Re: counting each repeated Items in Listview using vb6

    .........................................
    Last edited by falahjomor; December 4th, 2011 at 12:36 PM.

  5. #20
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  6. #21
    Join Date
    Nov 2002
    Posts
    278

    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

  7. #22
    Join Date
    Oct 2011
    Location
    Malaysia , Selangor
    Posts
    89

    Re: counting each repeated Items in Listview using vb6

    Quote Originally Posted by DinoVaught View Post
    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

  8. #23
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  9. #24
    Join Date
    Nov 2002
    Posts
    278

    Re: counting each repeated Items in Listview using vb6

    Quote Originally Posted by falahjomor View Post
    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.

  10. #25
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

  11. #26
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: counting each repeated Items in Listview using vb6

    ????

  12. #27
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: counting each repeated Items in Listview using vb6

    Quote Originally Posted by WoF View Post
    ????
    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.

  13. #28
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: counting each repeated Items in Listview using vb6

    Reported
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  14. #29
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    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...

  15. #30
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured