Professional Web Applications Themes

To count Words of a Sentence - Microsoft Access

Frank, To count the number of words in a field, count the number of spaces and add 1. This assumes there are no double spaces within the field. Add the following function to a module: Public Function CountWords(InText as String) as Integer ' Count the number of words in a field. Dim intX As Integer Dim intY As Integer Dim intCount As Integer intX = InStr(1, InText, Chr(32)) Do While intX <> 0 intCount = intCount + 1 intY = intX + 1 intX = InStr(intY, InText, Chr(32)) Loop CountWords = intCount + 1 End Function You can call the ...

  1. #1

    Default Re: To count Words of a Sentence

    Frank,
    To count the number of words in a field, count the number of spaces and add
    1. This assumes there are no double spaces within the field.

    Add the following function to a module:

    Public Function CountWords(InText as String) as Integer
    ' Count the number of words in a field.

    Dim intX As Integer
    Dim intY As Integer
    Dim intCount As Integer
    intX = InStr(1, InText, Chr(32))
    Do While intX <> 0
    intCount = intCount + 1
    intY = intX + 1
    intX = InStr(intY, InText, Chr(32))
    Loop
    CountWords = intCount + 1

    End Function

    You can call the function from a query:
    WordCount:CountWords([txtNome])

    Add criteria and/or error handling to test for Null records.



    --
    Fred

    Please reply only to this newsgroup.
    I do not reply to personal e-mail.


    "Frank Dulk" <fdulkbol.com.br> wrote in message
    news:uqZ6hmSVDHA.1832TK2MSFTNGP09.phx.gbl...
    >
    >
    >
    > do I have a sentence in a text box called txtnome, how to count this text
    > box's words that are separate for space??
    >
    >

    Fredg Guest

  2. #2

    Default Re: To count Words of a Sentence

    Thank you,
    How do I make using code vba to catch the (amount of entrance - amount of
    exit) / sum (entrance values - exit values) of a certain product?


    I make that using a query, but I don't know as doing using vba.

    but the one that I am not getting is to recover those values.


    (amount of entrance - amount of exit) / sum (entrance values -
    exit values)

    something as:

    dsum ("amount of entrance","tbl","product = number and movimento = "e")

    dsum ("amount of exit","tbl","product = number and movimento = "s")


    "Fredg" <fgutkindatt.net> escreveu na mensagem
    news:PddVa.77861$0v4.5153722bgtnsc04-news.ops.worldnet.att.net...
    > Frank,
    > To count the number of words in a field, count the number of spaces and
    add
    > 1. This assumes there are no double spaces within the field.
    >
    > Add the following function to a module:
    >
    > Public Function CountWords(InText as String) as Integer
    > ' Count the number of words in a field.
    >
    > Dim intX As Integer
    > Dim intY As Integer
    > Dim intCount As Integer
    > intX = InStr(1, InText, Chr(32))
    > Do While intX <> 0
    > intCount = intCount + 1
    > intY = intX + 1
    > intX = InStr(intY, InText, Chr(32))
    > Loop
    > CountWords = intCount + 1
    >
    > End Function
    >
    > You can call the function from a query:
    > WordCount:CountWords([txtNome])
    >
    > Add criteria and/or error handling to test for Null records.
    >
    >
    >
    > --
    > Fred
    >
    > Please reply only to this newsgroup.
    > I do not reply to personal e-mail.
    >
    >
    > "Frank Dulk" <fdulkbol.com.br> wrote in message
    > news:uqZ6hmSVDHA.1832TK2MSFTNGP09.phx.gbl...
    > >
    > >
    > >
    > > do I have a sentence in a text box called txtnome, how to count this
    text
    > > box's words that are separate for space??
    > >
    > >
    >
    >

    Frank Dulk Guest

  3. #3

    Default Re: To count Words of a Sentence

    Dim s() As String
    Dim text As String
    text = "Now is the time for all good men to come to the aid of their country"
    s = Split(text, " ")
    MsgBox "Word Count Is " & CStr(UBound(s) + 1)






    "Fredg" <fgutkindatt.net> wrote in message
    news:PddVa.77861$0v4.5153722bgtnsc04-news.ops.worldnet.att.net...
    > Frank,
    > To count the number of words in a field, count the number of spaces and add
    > 1. This assumes there are no double spaces within the field.
    >
    > Add the following function to a module:
    >
    > Public Function CountWords(InText as String) as Integer
    > ' Count the number of words in a field.
    >
    > Dim intX As Integer
    > Dim intY As Integer
    > Dim intCount As Integer
    > intX = InStr(1, InText, Chr(32))
    > Do While intX <> 0
    > intCount = intCount + 1
    > intY = intX + 1
    > intX = InStr(intY, InText, Chr(32))
    > Loop
    > CountWords = intCount + 1
    >
    > End Function
    >
    > You can call the function from a query:
    > WordCount:CountWords([txtNome])
    >
    > Add criteria and/or error handling to test for Null records.
    >
    >
    >
    > --
    > Fred
    >
    > Please reply only to this newsgroup.
    > I do not reply to personal e-mail.
    >
    >
    > "Frank Dulk" <fdulkbol.com.br> wrote in message
    > news:uqZ6hmSVDHA.1832TK2MSFTNGP09.phx.gbl...
    > >
    > >
    > >
    > > do I have a sentence in a text box called txtnome, how to count this text
    > > box's words that are separate for space??
    > >
    > >
    >
    >

    MikeB Guest

  4. #4

    Default Re: To count Words of a Sentence

    Dim s() As String
    Dim text As String
    text = "Now is the time for all good men to come to the aid of their country" 'has double space
    between "the" and "time"
    s = Split(Trim(Replace(text, " ", " ")), " ")

    MsgBox "Word Count Is " & CStr(UBound(s) + 1)


    "Mike Painter" <mpainteratattdotnet> wrote in message
    news:2c930f71199d916336d83bfeac3e8e66free.teranew s.com...
    >
    > "Fredg" <fgutkindatt.net> wrote in message
    > news:PddVa.77861$0v4.5153722bgtnsc04-news.ops.worldnet.att.net...
    > > Frank,
    > > To count the number of words in a field, count the number of spaces and
    > add
    > > 1. This assumes there are no double spaces within the field.
    > >
    > > Add the following function to a module:
    > >
    > > Public Function CountWords(InText as String) as Integer
    > > ' Count the number of words in a field.
    > >
    > > Dim intX As Integer
    > > Dim intY As Integer
    > > Dim intCount As Integer
    > > intX = InStr(1, InText, Chr(32))
    > > Do While intX <> 0
    > > intCount = intCount + 1
    > > intY = intX + 1
    > > intX = InStr(intY, InText, Chr(32))
    > > Loop
    > > CountWords = intCount + 1
    > >
    > > End Function
    >
    > This works but if there are two or more spaces together it will be an
    > incorrect count.
    >
    > Sigh. If Gates had copied Pick Basic it would be:
    > Text = trim(text) 'which trims both ends and reduces all spaces to a single
    > space.
    > wordcount = count(Text, " ") + 1
    >
    >
    >

    MikeB Guest

  5. #5

    Default Re: To count Words of a Sentence

    I forgot about the split function which is relatively new and can't find
    Replace in Access.
    If Replace is recursive it would work, if not text = "Now hear
    This." would be a (trivial) problem.
    "MikeB" <m.byerleyATVerizontDOTnet> wrote in message
    news:u$DRTLWVDHA.2288TK2MSFTNGP12.phx.gbl...
    > Dim s() As String
    > Dim text As String
    > text = "Now is the time for all good men to come to the aid of their
    country" 'has double space
    > between "the" and "time"
    > s = Split(Trim(Replace(text, " ", " ")), " ")
    >
    > MsgBox "Word Count Is " & CStr(UBound(s) + 1)
    >
    >
    > "Mike Painter" <mpainteratattdotnet> wrote in message
    > news:2c930f71199d916336d83bfeac3e8e66free.teranew s.com...
    > >
    > > "Fredg" <fgutkindatt.net> wrote in message
    > > news:PddVa.77861$0v4.5153722bgtnsc04-news.ops.worldnet.att.net...
    > > > Frank,
    > > > To count the number of words in a field, count the number of spaces
    and
    > > add
    > > > 1. This assumes there are no double spaces within the field.
    > > >
    > > > Add the following function to a module:
    > > >
    > > > Public Function CountWords(InText as String) as Integer
    > > > ' Count the number of words in a field.
    > > >
    > > > Dim intX As Integer
    > > > Dim intY As Integer
    > > > Dim intCount As Integer
    > > > intX = InStr(1, InText, Chr(32))
    > > > Do While intX <> 0
    > > > intCount = intCount + 1
    > > > intY = intX + 1
    > > > intX = InStr(intY, InText, Chr(32))
    > > > Loop
    > > > CountWords = intCount + 1
    > > >
    > > > End Function
    > >
    > > This works but if there are two or more spaces together it will be an
    > > incorrect count.
    > >
    > > Sigh. If Gates had copied Pick Basic it would be:
    > > Text = trim(text) 'which trims both ends and reduces all spaces to a
    single
    > > space.
    > > wordcount = count(Text, " ") + 1
    > >
    > >
    > >
    >
    >

    Mike Painter Guest

  6. #6

    Default Re: To count Words of a Sentence

    Well, If you want Replace to work recursively, you would pass the text string to a function and call
    itself recursively until there are no more double spaces, Like:

    Private Sub StartHere()
    Dim s() As String
    Dim text As String
    text = DropDubSpace(Trim("Now is the time for all good men to come to the aid of their
    country "))
    s = Split(text, " ")
    MsgBox "Word Count Is " & CStr(UBound(s) + 1)

    End Sub

    Private Function DropDubSpace(ByVal sTextIN As String) As String
    sTextIN = Replace(sTextIN, " ", " ")
    If (InStr(1, sTextIN, " ") > 0) Then
    sTextIN = DropDubSpace(sTextIN)
    Else
    DropDubSpace = sTextIN
    End If
    DropDubSpace = sTextIN
    End Function



    "Mike Painter" <mpainteratattdotnet> wrote in message
    news:630feaa8b7f96710f6b86d3ab111dae5free.teranew s.com...
    > I forgot about the split function which is relatively new and can't find
    > Replace in Access.
    > If Replace is recursive it would work, if not text = "Now hear
    > This." would be a (trivial) problem.
    > "MikeB" <m.byerleyATVerizontDOTnet> wrote in message
    > news:u$DRTLWVDHA.2288TK2MSFTNGP12.phx.gbl...
    > > Dim s() As String
    > > Dim text As String
    > > text = "Now is the time for all good men to come to the aid of their
    > country" 'has double space
    > > between "the" and "time"
    > > s = Split(Trim(Replace(text, " ", " ")), " ")
    > >
    > > MsgBox "Word Count Is " & CStr(UBound(s) + 1)
    > >
    > >
    > > "Mike Painter" <mpainteratattdotnet> wrote in message
    > > news:2c930f71199d916336d83bfeac3e8e66free.teranew s.com...
    > > >
    > > > "Fredg" <fgutkindatt.net> wrote in message
    > > > news:PddVa.77861$0v4.5153722bgtnsc04-news.ops.worldnet.att.net...
    > > > > Frank,
    > > > > To count the number of words in a field, count the number of spaces
    > and
    > > > add
    > > > > 1. This assumes there are no double spaces within the field.
    > > > >
    > > > > Add the following function to a module:
    > > > >
    > > > > Public Function CountWords(InText as String) as Integer
    > > > > ' Count the number of words in a field.
    > > > >
    > > > > Dim intX As Integer
    > > > > Dim intY As Integer
    > > > > Dim intCount As Integer
    > > > > intX = InStr(1, InText, Chr(32))
    > > > > Do While intX <> 0
    > > > > intCount = intCount + 1
    > > > > intY = intX + 1
    > > > > intX = InStr(intY, InText, Chr(32))
    > > > > Loop
    > > > > CountWords = intCount + 1
    > > > >
    > > > > End Function
    > > >
    > > > This works but if there are two or more spaces together it will be an
    > > > incorrect count.
    > > >
    > > > Sigh. If Gates had copied Pick Basic it would be:
    > > > Text = trim(text) 'which trims both ends and reduces all spaces to a
    > single
    > > > space.
    > > > wordcount = count(Text, " ") + 1
    > > >
    > > >
    > > >
    > >
    > >
    >
    >

    MikeB Guest

Similar Threads

  1. #39264 [Opn->Bgs]: Problem with IF sentence
    By derick@php.net in forum PHP Bugs
    Replies: 0
    Last Post: October 26th, 11:52 AM
  2. Showing the first sentence of a paragraph
    By Micheller in forum Macromedia ColdFusion
    Replies: 8
    Last Post: May 2nd, 08:34 PM
  3. Sentence Drag
    By Flash_Neophyte webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 0
    Last Post: February 6th, 05:54 PM
  4. replace words with bold words
    By Lasse Edsvik in forum ASP
    Replies: 9
    Last Post: October 7th, 01:19 PM
  5. Sentence /paragraph spacing
    By pyrolabs webforumsuser@macromedia.com in forum Macromedia Dreamweaver
    Replies: 1
    Last Post: July 8th, 08:52 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139