Hi,

I'm trying to count the number of words in a textbox. I use the following code. But when I press the space bar twice, my word count is wrong because it's counting the space as a word. Can you please help me.


Dim oneChar As String

Dim i As Integer

Dim x As Integer

Dim howlong As Integer

howlong = Len(txtMaintext.Text) ' Parse through the characters in the string

For i = 1 To howlong

oneChar = Mid$(txtMaintext.Text, i, 1) ' Get a character

If oneChar = " " Then x = x + 1

txtNumWords.Text = x + 1 'This is the words count in the textbox

Next