need help to find code to count words inside a textbox using visual basic 6
i tried this code but there was an error
Private Sub Button1_Click(ByVal sender As System.Object,

ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String
Dim i, l, words As Integer
str = TextBox1.Text
str = LTrim(str) 'removes leading blank spaces
str = RTrim(str) ' removes trailing blank spaces
l = str.Length
i = 0
words = 0
While (i < l)
If str(i) = " " Then
words = words + 1
i = i + 1
While str(i) = " " ' removes continuous blank spaces
i = i + 1
End While
Else
i = i + 1
End If

End While
words = words + 1 ' adds the last word
MessageBox.Show("WORDS =" & words)
End Sub

please help