Count number of words
Count number of words
Rate Count number of words
(1(1 Vote))
'and Follow the following codes given,,,
Private Sub Command1_Click()
Dim position As Long
Dim words As Long
Dim myText As String
position = 1
myText = Text1.Text
' massage string:
' replace line feeds with spaces
myText = Replace(myText, Chr(13) & Chr(10), " ")
' replace tabs with single spaces
myText = Replace(myText, Chr(9), " ")
myText = Trim(myText)
' Count the first word
' Because the last word isn't delimited by
' a space, if the string isn't blank, then it
' contains at least one word.
' By setting words=1, we won't have to increase the
' number of words by 1 when we are done counting.
If Len(myText) > 0 Then words = 1
' while the string contains spaces...
Do While position > 0
position = InStr(position, myText, " ")
' ... increase word count
If position > 0 Then
words = words + 1
' and skip additional spaces
While Mid(myText, position, 1) = " "
position = position + 1
Wend
End If
Loop
MsgBox "The TextBox contains " & words & " words"
End Sub
Count number of words Comments
No comments yet — be the first to post one!
Post a Comment