I have put some code in an array and I would like to create a list of each word, and how many times it appears in the array. I can parse thru the code, but I am having duplication. Everything I have thought of has to do with going thru the list over and over, that obviously isn't productive. Below is my code. I would be very greatful if someone could help me find an efficient way of doing this. The code should put the "word (count)" on each line, which I can format.
Thank you for the help.
As you can see, the function returns the string, which will be placed in a rich text box.Code:Public Function WORD_COUNT(ByVal StringToCount As String) As String On Error GoTo ErrorHandler Dim WordsToCount As Variant Dim intIndex As Integer Dim ScanCount As Integer Dim CurrentWord As String Dim WordCount As Integer Dim FinishedText As String WordCount = 0 WordsToCount = Split(StringToCount, Chr(32)) For intIndex = 0 To UBound(WordsToCount) CurrentWord = WordsToCount(intIndex) WordCount = 1 For ScanCount = 0 To UBound(WordsToCount) If ScanCount <> intIndex Then If WordsToCount(ScanCount) = CurrentWord Then WordCount = WordCount + 1 End If End If Next FinishedText = FinishedText & CurrentWord & "(" & WordCount & ")" & vbCrLf Next WORD_COUNT = FinishedText Exit Function ErrorHandler: ErrorHandler.ErrorAlert Err.Number, Err.Description, "clsPageParcer.WORD_COUNT" End Function




Reply With Quote