How do I do string processing with arrays for double words?

VBMaster was able to help me put this little program together that demonstrates how to take input from one text box and process it for sql query search string.

The program works fine for single words with operators, example:

windows and display

I would like it to work for double words like the following examples:

-windows 95 and display properties
-windows 95 and display
-windows and display properties, etc.

full points for full source code demonstrating this.

Here is my present code for single words:

--------------------------------------
Dim sOperators() As String
  Dim sWords() As String
  Dim sArray As Variant
  Dim a As Integer
  Dim sSQL As String
 
   
Private Sub cmdProcess_Click()

PrimaryInput = Text1.Text

sArray = Split(PrimaryInput)


  ReDim sWords(UBound(sArray) \ 2)
  ReDim sOperators(UBound(sArray) \ 2 - 1)
  For a = 0 To (UBound(sArray) - 1) Step 2
    sWords(a \ 2) = sArray(a)
    sOperators(a \ 2) = sArray(a + 1)
  Next
  sWords(a \ 2) = sArray(a)
 
 
  sSQL = "select * from windows where"
  For a = 0 To (UBound(sWords) - 1)
    sSQL = sSQL & " problem like '%" & sWords(a) & "%' " & sOperators(a)
  Next
  sSQL = sSQL & " problem like '%" & sWords(a) & "%'"
Text2.Text = sSQL
End Sub
---------------------------------------
end of code
jawad_hussainAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

VbmasterCommented:
I posted some codes on the earlier question. Tell me how it works.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jawad_hussainAuthor Commented:
VbMaster's code works perfectly, here is the code:

-----------------------start of code
  Dim sOperators() As String
  Dim WordCount As Integer
  Dim OpCount As Integer
  Dim sWords() As String
  Dim sResult As String
  Dim sArray As Variant
  Dim a As Integer
  Dim PrimaryInput As String
 



 
Private Sub cmdProcess_Click()
PrimaryInput = Text1.Text
sArray = Split(PrimaryInput)
   
  sResult = ""
  Erase sOperators
  Erase sWords
  WordCount = 0
  OpCount = 0
  a = 0
   
  If (UBound(sArray) = 0) Then
    WordCount = 1
    ReDim sWords(WordCount - 1)
    sWords(WordCount - 1) = sArray(0)
    sResult = sArray(0)
  Else
    WordCount = 1
    ReDim sWords(WordCount - 1)
    Do Until (a > UBound(sArray))
      sResult = sResult & sArray(a)
      Select Case UCase$(sArray(a))
      Case "AND", "OR"
        OpCount = OpCount + 1
        ReDim Preserve sOperators(OpCount - 1)
        sOperators(OpCount - 1) = sArray(a)
        WordCount = WordCount + 1
        ReDim Preserve sWords(WordCount - 1)
      Case Else
        If (Len(sWords(WordCount - 1)) > 0) Then
          sWords(WordCount - 1) = sWords(WordCount - 1) & " " & sArray(a)
        Else
          sWords(WordCount - 1) = sArray(a)
        End If
      End Select
      a = a + 1
    Loop
  End If

   
  Dim sSQL As String
    sSQL = "select * from windows where"
  For a = 0 To (WordCount - 2)
    sSQL = sSQL & " problem like '%" & sWords(a) & "%' " & sOperators(a)
  Next
  sSQL = sSQL & " problem like '%" & sWords(a) & "%'"
 
  Text2.Text = sSQL
End Sub

-----------------------END OF CODE
0
jawad_hussainAuthor Commented:
Thanks for the great answer, I've accepted your answer. and posted the code at the bottom.
0
jawad_hussainAuthor Commented:
VBMaster:

I tried changing the case clause to also include "AND NOT" but it does not seem to work.

do you have any idea?

Case "AND", "OR", "AND NOT"
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.