473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.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
Jun 12 '12 #1
1 1851
Killer42
8,435 Expert 8TB
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.
Jun 22 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: NikkoW | last post by:
I need to assign a string to a variable but the text string includes quotation marks: Example: MyString = "He turned and said "Hello" before leaving." When the compiler hits the quotation...
8
by: Stephen Poley | last post by:
One disadvantage of using a simple text editor to produce HTML is that it is relatively time-consuming to put in the proper typographical quotation marks and dashes. A round tuit having arrived...
63
by: Tristan Miller | last post by:
Greetings. Do any popular browsers correctly support <q>, at least for Western languages? I've noticed that Mozilla uses the standard English double-quote character, ", regardless of the lang...
7
by: Paradigm | last post by:
I am trying to create a recordset where some text fields are matching. The problem is that some of the text fields contain quotation marks. I have tried to create the sql string using replace eg....
0
by: Aaron Deskins | last post by:
Hello all, I'm trying to set up a database to track articles and documents. I've created a Table to hold the information I need. I've set up one of the fields to hold the actual text of the...
2
by: Dixie | last post by:
Hi, I am tyring to write some generic code that will send the source SQL for a mailmerge to a Word template. I am trying to use DLookup to insert the query name that is the record source for the...
3
by: Ufit | last post by:
Simple,dumm question - how to include quotation marks in the string? F.ex. "Data Source=.\SQLEXPRESS;AttachDbFilename="C:\client data.mdf";Integrated Security=True;User Instance=True" I get syntax...
1
by: nonni | last post by:
Hi. I came across this site while looking for a function to replace Quotation marks in SQL. This is my code. <!-- Begin Code --> Intro = Replace(Intro,"'","''") Text =...
31
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and...
3
by: Junior | last post by:
I want to open a text file for reading and delineate it by comma. I also want any data surrounded by quotation marks that has a comma in it, not to count the commas inside the quotation marks ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.