View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Parsing out text entries in a text box

maybe it is a misunderstanding of intent. When you do the split, the space
between words is removed. That is why I am checking 250 and not 500. I am
not sure what happens with multiple spaces in a row as I am not sure what
you are trying to achieve with your limitation.


I just tested and it appears if a space is present, there will an element in
the array for each side of the space. I tested with 5 spaces in a single
string and got 6 elements (but the elements were empty since there is
nothing between the spaces.

? ubound(split(" "," "))
5
? Len(split(" "," ")(1))
0
0
? ubound(split("1 1 1 1 1 1"," "))
5

so I don't think you are correct in saying the space goes with the word - it
is discarded. With that information, perhaps you can refine the code to
achieve what you want.

--
Regards,
Tom Ogilvy





"jasonsweeney " wrote in
message ...
Tom,

I changed the number from 250 to 20 in the code you sent me to test
when somebody reaches the limit....

With the code as I copied above, I got an error....I just erased the
offending line, and now it works....my code now is:

____________
Private Sub plaintextbox_Change()
Dim varr
ReDim varr(0 To 1)
varr = Split(plaintextbox.Text, " ")
wordcount.Caption = UBound(varr)
If UBound(varr) - 1 = 14 Then
MsgBox "You are reaching the limit of 20 words"
ElseIf UBound(varr) - 1 = 20 Then
MsgBox "You have reached the limit of 20 words"
ReDim Preserve varr(0 To 19)
End If
__________________

Also, on the space as a word issue. If I just hit the space bar, the
spaces count as words. What appears to be happening is that a space
occuring after a word is considered "part" of the preceding word.
Weird.


---
Message posted from http://www.ExcelForum.com/