|
Sub Command1_Click ()
ReDim astrWords(2) As String Dim intLCV As Long subGetWords(Text1.Text, astrWords()) List1.Clear For intLCV = 0 To UBound(astrWords) List1.AddItem astrWords(intLCV) Next intLCV End Sub Sub subGetWords (ByVal vstrSentence As String, rastrWords() As String) Dim lngNoOfWords As Long Dim lngLCV As Long Dim lngRowNo As Long Dim strSentenceChar As String 'count the number of words. Number of words = number of spaces plus one For lngLCV = 1 To Len(vstrSentence) If Mid$(vstrSentence, lngLCV, 1) = Space$(1) Then lngNoOfWords = lngNoOfWords + 1 End If Next lngLCV 'make the array big enough to hold the words ReDim rastrWords(lngNoOfWords + 1) 'put each word into a row in the array 'lngRowNo = 0 For lngLCV = 1 To Len(vstrSentence) strSentenceChar = Mid$(vstrSentence, lngLCV, 1) If strSentenceChar Space$(1) Then rastrWords(lngRowNo) = rastrWords(lngRowNo) & strSentenceChar Else lngRowNo = lngRowNo + 1 End If Next lngLCV End Sub |