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.Text, ",", "AND")
Text1.Text = NewtxtAND
'IF CLICKED AGAIN
OldtxtAND = Text1.Text
NewtxtAND = Replace(Text1.Text, "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(myarr(i)), " ") > 0 then
myarr(i) = """" & trim(myarr(i)) & """"
else: Myarr(i) = trim(myarr(i))
end if
next
mystr = join(myarr, " and ")
msgbox mystr