hello everyone

i'm writing a program that finds out how many times a word has been repeated in a string

this is what i did
VB Code:
  1. Dim chkstr(1 To 10) As String
  2.  
  3. temp = rtb.Text
  4.  
  5. Do While i <= Len(temp)
  6.  
  7. i = i + 1
  8. chkstr(i) = Mid$(temp, 1, InStr(1, temp, Chr(32)))
  9.  
  10. temp = Mid$(temp, InStr(1, temp, Chr(32)) + 1, Len(temp))
  11.  
  12. If InStr(1, temp, Chr(32)) <= 0 Then
  13.  
  14. chkstr(i) = temp
  15.  
  16. Exit Do
  17.  
  18. End If
  19.  
  20. Loop

this adds all the words to the chkstr() array

now
the following should check if any word was repeated again before in the string
VB Code:
  1. Dim wrdtoken(1 to 10) As Integer
  2.  
  3. For i = 2 To numWords
  4.  
  5.     For j = 1 To i - 1
  6.  
  7.         If StrComp(chkstr(i), chkstr(j), vbTextCompare) = 0 Then
  8.            
  9.             wrdtoken(i) = wrdtoken(i) + 1
  10.          Else
  11.  
  12.             unique = False
  13.            
  14.         End If
  15.     Next j
  16.  
  17. Next i

the numWords function::

VB Code:
  1. Public Function NumWords() As Integer
  2. Dim i As Integer
  3. Dim temp As String
  4. i = 0
  5. temp = rtb.Text
  6.  
  7. Do While i <= Len(temp)
  8. i = i + 1
  9. temp = Mid$(temp, InStr(1, temp, Chr(32)) + 1, Len(temp))
  10. If InStr(1, temp, Chr(32)) <= 0 Then Exit Do
  11. Loop
  12.  
  13. numwords = i
  14. End Function

but it doesnt work the way i thought it would.....any suggestions please