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:
Dim chkstr(1 To 10) As String temp = rtb.Text Do While i <= Len(temp) i = i + 1 chkstr(i) = Mid$(temp, 1, InStr(1, temp, Chr(32))) temp = Mid$(temp, InStr(1, temp, Chr(32)) + 1, Len(temp)) If InStr(1, temp, Chr(32)) <= 0 Then chkstr(i) = temp Exit Do End If 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:
Dim wrdtoken(1 to 10) As Integer For i = 2 To numWords For j = 1 To i - 1 If StrComp(chkstr(i), chkstr(j), vbTextCompare) = 0 Then wrdtoken(i) = wrdtoken(i) + 1 Else unique = False End If Next j Next i
the numWords function::
VB Code:
Public Function NumWords() As Integer Dim i As Integer Dim temp As String i = 0 temp = rtb.Text Do While i <= Len(temp) i = i + 1 temp = Mid$(temp, InStr(1, temp, Chr(32)) + 1, Len(temp)) If InStr(1, temp, Chr(32)) <= 0 Then Exit Do Loop numwords = i End Function
but it doesnt work the way i thought it would.....any suggestions please




Reply With Quote