Add Quotation Marks every TWO words in Text Box

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BarbasHamilcar
    New Member
    • Jun 2012
    • 1

    Add Quotation Marks every TWO words in Text Box

    Hi guys,

    I am really stuck here, hope you guys can help me crack this thing.

    So I have a text box where the user would add Search Terms separated by a comma. since the Search terms will be variable in lenght and word count, I have no way to specifically define a # of characters long to add a quotation mark.



    Here is what the text box could be:

    Text box contents example:
    (Java, Linux, Unix, Product Manager, Software Engineer)

    So my code will replace the commas and translate into this:

    (Java AND Linux AND Unix AND Product Manager AND Software Engineer)

    MY ISSUE IS:

    How do I get VB6 to evaluate terms like: Product Manager and Software Engineer that WILL need quotations in between to be properly recognized as a SINGLE search term.

    NOTE: I did this in Excel 2007 with no problems, using the TextTocolumns and a delimited table, so I splitted each term into a column and ran individual evaluations to quote based on a word count formula.

    BUT translating this into VB6 without the TextToColumns is a pain in the ass.

    SAMPLE CODE OF WHAT I GOT SO FAR:


    Dim Counter As Integer
    Dim StartPos As Integer
    Dim NumOfWords
    Dim OldtxtAND As String
    Dim NewtxtAND As String
    Dim OldtxtOR As String
    Dim NewtxtOR As String
    Dim OldtxtNOT As String
    Dim NewtxtNOT As String

    'Variables Defined for String evaluation ( replace commas by Operator )


    'AND OPERATOR FIELD
    Text1 = Trim(Text1) ' Remove All Spaces
    While InStr(1, Text1, " ") > 0 'Remove Single Spaces
    StartPos = InStr(1, Text1, " ")
    Text1 = Mid(Text1, 1, StartPos - 1) & _
    Mid(Text1, StartPos + 1, Len(Text1) - StartPos)
    Wend

    While InStr(1, Text1, " ") > 0 'Remove Double Spaces
    StartPos = InStr(1, Text1, " ")
    Text1 = Mid(Text1, 1, StartPos - 1) & _
    Mid(Text1, StartPos + 1, Len(Text1) - StartPos)
    Wend

    OldtxtAND = Text1.Text
    NewtxtAND = Replace(Text1.T ext, ",", "AND")
    Text1.Text = NewtxtAND

    'IF CLICKED AGAIN
    OldtxtAND = Text1.Text
    NewtxtAND = Replace(Text1.T ext, "AND", " AND ")
    Text1.Text = NewtxtAND
    ' FINISHED THE AND OPERATOR COMMA REPLACE


    SO THE FINAL RESULT NEEDS TO BE:

    Java AND Linux AND Unix AND "Product Manager" AND "Software Engineer"







    THIS IS THE RESOLVED CODE:

    mystr = "java, linux, unix, product manager, software engineer"
    myarr = split(mystr, ",")
    for i = 0 to ubound(myarr)
    if instr(trim(myar r(i)), " ") > 0 then
    myarr(i) = """" & trim(myarr(i)) & """"
    else: Myarr(i) = trim(myarr(i))
    end if
    next
    mystr = join(myarr, " and ")
    msgbox mystr
    Last edited by BarbasHamilcar; Jun 12 '12, 11:38 AM. Reason: ISSUE RESOLVED
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    You don't need to do all of the work yourself. Check out the Split function, it'll allow you to take your string and split it into an array based on the commas. It's sort of the opposite of Join. Then just stick the parts back together with AND between them, the way you are now.

    By the way, I highly recommend you get into the habit of indenting your code to show the structure. It makes it much easier to follow the logic.

    Comment

    Working...