I am a beginner...trying to get information on how to count words,sentences etc. in text being entered. There are many buggy problems with it. Any advice is already appreciated! Even where to look it up myself.
Printable View
I am a beginner...trying to get information on how to count words,sentences etc. in text being entered. There are many buggy problems with it. Any advice is already appreciated! Even where to look it up myself.
Hi,
Try using the Len(String x) function. It returns the length of the string.
HTH,
Preeti
Hi,
I reread your question, and I don't think that I answered it.
To count words we will assume that each word is seperated by a space so...
Private Function WordCount(Sentence As String) As Integer
Dim iPos As String 'Position of space in string
Dim TotalWords As Integer 'Number of words in string
Dim EOS As Boolean 'End Of String Flag
Dim iStart As Integer 'Starting position to search
iStart = 1 'Initialize to 1
Do Until EOS
iPos = InStr(Trim(Mid(Sentence, iStart)), " ")
TotalWords = TotalWords + 1
If iPos = 0 Then 'If no spaces were found
EOS = True
Else
iStart = iStart + iPos 'Start searching after the space
End If
Loop
WordCount = TotalWords
End Function
HTH,
Preeti