Results 1 to 3 of 3

Thread: ***----Counting Words----****

  1. #1

    Thread Starter
    Lively Member mykg4orce's Avatar
    Join Date
    Oct 2000
    Location
    CANADA
    Posts
    92

    Exclamation

    How can words be counted in a text box??
    similar to the function a word processor has.


    Secondly how do count all the words greater than 8 characters in the same text box????

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Code:
        Dim vArray As Variant
        Dim intIndex As Integer
        Dim intCount As Integer
        
        ' Split the text into words. A problem here is that
        ' each extra space (over one) between words is count _
        ' as a word.
        vArray = Split(Text1.Text, " ")
        
        ' Find those longer than 8
        For intIndex = 0 To UBound(vArray)
            If Len(vArray(intIndex)) > 8 Then
                intCount = intCount + 1
            End If
        Next
            
        MsgBox "Text1 contains " & UBound(vArray) + 1 & " words " _
             & "of which " & intCount & " are longer than 8 characters"

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Here's an improvement

    Code:
        Dim vArray As Variant
        Dim intIndex As Integer
        Dim intCount As Integer
        Dim intWords As Integer
        
        ' Split the text into words.
        vArray = Split(Text1.Text, " ")
        
        ' Find those longer than 8
        For intIndex = 0 To UBound(vArray)
            If Len(vArray(intIndex)) > 8 Then
                intCount = intCount + 1
            End If
            If Trim(vArray(intIndex)) <> "" Then
                intWords = intWords + 1
            End If
        Next
            
        MsgBox "Text1 contains " & intWords & " words " _
             & "of which " & intCount & " are longer than 8 characters"

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