Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text Eliminate multiple spaces 1

Status
Not open for further replies.

Domino2

Technical User
Jun 8, 2008
475
GB
I have a textbox on a form that spits out individual words comma seperated into a variable HTT

HTT = Replace(Me.BSUM.Text, " ", ",")
It works well, however is not protected against more than one hit on the spacebar between words.

I tried HTT = Replace(Trim(Me.BSUM.Text), " ", ",") but it only worked after the second word had been typed.

Thanks

 
I'm not sure that I completely understand what you're saying, here, but I think you need to try replacing any 'double spaces' first, then adding your delimiter:
Code:
HTT = Replace(Me.BSUM.Text, "  ", " ")
HTT = Replace(Me.HTT, " ", ",")

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Sorry, if HTT is a variable, the second line should simply read

Code:
HTT = Replace(HTT, " ", ",")

The Missinglinq

Richmond, Virginia

The Devil's in the Details!
 
Thanks. However I get the same problems.

If I type a word in the text box and then add more than one space, and then add another word and do the same etc etc, then I end up with an unwanted large space between the first and second words, but after that it's ok, the spaces are corrected.

Maybe it's further down the line the problem exists. After text has been entered in the textbox, the words get split into indidual words and put into a listbox


Code:
' Remove Orphan Comma at end of word string
    GG = Len(Trim(HTT))
    If Right(Trim(HTT), 1) = "," Then
        HTT = Left(HTT, GG - 1)
    End If

    tblKeywords = HTT    'This is the text separated into words with commas
    TmpKeywords = Split(tblKeywords, ",")

    ' ---------------------------------------------------------------------------

    For i = LBound(TmpKeywords) To UBound(TmpKeywords)
        LKS = TmpKeywords(i)

    This then gets added into a list box
 
Why not simply use the space separated list instead of converting spaces to commas for splitting?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, I could have done, did not think at the time.
Thanks Randy700, good idea, but did not sort problem, however you got me nearer.

For i = LBound(TmpKeywords) To UBound(TmpKeywords)
LKS = TmpKeywords(i)
If Trim(LKS) = "" Then GoTo Z1

I stepped through the code and I was getting spaces which having now trapped has fixed it.

Thanks both
 
It seems my problem is in this line

HTT = Replace(Me.BSUM.Text, " ", ",")

I looked at HTT after putting in 3 words with 3 over entered spaces and I am getting this

HTT="One,,,,Two,,,,Three,,,,"

Is there a cleaner way to break up text typed in a text box into single words separated by a single comma between each word. I am trying to keep it in this format as wanted for something else later. Thanks
 
Replace this:
[tt]HTT = Replace(Me.BSUM.Text, " ", ",")[/tt]
with this:
Code:
HTT = Trim(Me.BSUM.Text)
While InStr(HTT, "  "): HTT = Replace(HTT, "  ", " "): WEnd
HTT = Replace(HTT, " ", ",") ' again, why comma instead of space ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thank you PHV, that works perfectly.
It is a request to be able to export a comma delimited file although nobody can tell me why at the moment.
But thanks for fixing this one.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top