zaphodz34
10-02-2001, 06:25 AM
This is one I'm finding quite tough....
I have a txtBox into which I'm adding letters to form words ....
I want to write a function which when called will return the amount for words I have typed.......I will probably used a menu to display the returned value.....At the moment I'm struggling with functions....so any help would be appreciated
Cheers ........
presuming you are not checking for proper words then something like this should work
<pre><font color=blue>Dim</font color=blue> strTest <font color=blue>As String</font color=blue>
<font color=blue>Dim</font color=blue> intWords <font color=blue>As Integer</font color=blue>
<font color=blue>Dim</font color=blue> booWord <font color=blue>As Boolean</font color=blue>
strTest = Text1.Text
<font color=blue>For</font color=blue> x = 1 <font color=blue>To</font color=blue> Len(strTest)
<font color=blue>If</font color=blue> booWord = <font color=blue>False Then</font color=blue>
<font color=blue>If</font color=blue> Mid(strTest, x, 1) <> " " <font color=blue>Then</font color=blue>
intWords = intWords + 1
booWord = <font color=blue>True</font color=blue>
<font color=blue>End If</font color=blue>
<font color=blue>Else</font color=blue>
<font color=blue>If</font color=blue> Mid(strTest, x, 1) = " " <font color=blue>Then</font color=blue> booWord = <font color=blue>False</font color=blue>
<font color=blue>End If</font color=blue>
<font color=blue>Next</font color=blue> x
Label1.Caption = intWords</pre>
Banjo
10-02-2001, 07:03 AM
You could also try this:<pre>Dim strTest as String
Dim words() as String
words = Split(strTest, " ")</pre>This places each word into an element in the array 'words'. I.e: If strTest = "This is a test"
<pre>words(0) = "This"
words(1) = "is"
words(2) = "a"
words(3) = "test"</pre>
Laurent
10-02-2001, 07:15 AM
then you simply do
ubound words()
this will give you the higher index of the array, the number of words
I'll be among the best soon, very soon!!!
Banjo
10-02-2001, 07:19 AM
Oh yeah, forgot about that bit. Cheers.
Laurent
10-02-2001, 07:27 AM
don't worry i was looking for split() but i didn't remember the name of the function!!!
I'll be among the best soon, very soon!!!