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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detect if single word

Status
Not open for further replies.

fileman1

Technical User
Feb 7, 2013
152
GB
I am using the split function. All was okay until someone just entered 1 word in a report text field. Can someone tell me how one can detect if only 1 word is in a string.
 
Not sure I understand. Split should happily work with just 1 word in the string being split.
 
Thanks. I am splitting up words in a sentence and having problems where just one word exists. I thought it was because it did not see more than one word, therefore I am trying to abort the split if only one word is there. Maybe this is not the problem, just wanted to isolate to see.
 
I have found why I have problems. Basic code below. The loop i was producing a single word ok, however produced a final output of "". So I have now added - 1 to my loop and I do not get a null final output.

Code:
Private Sub Command0_Click()
    Dim TmpKeywords() As String
    Dim tblKeywords As String
    Dim LLL As String
    Dim HHH As String
    Dim AAA As String
    Dim SSS As String

    AAA = "HELLO FRED"

    If Trim(AAA) > "" Then
        HHH = Trim(AAA)
        While InStr(HHH, "  "): HHH = Replace(HHH, "  ", " "): Wend
        HHH = Replace(HHH, " ", ",")
        LLL = LLL & HHH & ","
    End If


    tblKeywords = LLL
    TmpKeywords = Split(tblKeywords, ",")

    For i = LBound(TmpKeywords) To UBound(TmpKeywords) - 1
        LKS = TmpKeywords(i)
    Next i
End Sub

added -1 to line To UBound(TmpKeywords) - 1
Code is only rough, not my final code just to show problem I had



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top