ParseString




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

This code will read a textbox, and add each of its words in a
Listbox. This is useful for word counts, especially if you're
making a word processor If the code is modified by someone who
knows what he's doing, you could eventually use this code for
a spell checking engine (you'd have to have a dictionary, of
course), and although it would be slower than an OCX or a DLL,
it would be good enough for small strings.Follow these steps:
1. Create a new project. On the Form1, add a Textbox (Text1),
Commandbutton (Command1) and a Listbox (List1).
2. On the Text1, set the Multiline property to TRUE, and
Scrollbars to VERTICAL.
3. On the Command1, set the Caption to "List Words".
4. Add this code to the General Declarations section of
the Form:










( parsestring.html )- by Paolo Puglisi - Modifica del 17/12/2023