VB6 and Flexgrid

The search on flexgrid, code which i am using is given below..
issue is its throwing an error while the search didnt return any answer.. my flexgrid required one fixed row which carries the details about the fields..

  Dim target_name As String
  target_name = InputBox("Enter The Keyword you wish to Search", "Search")
  If Len(target_name) = 0 Then Exit Sub
  target_name = LCase$(target_name)

Dim r As Integer
Dim c As Integer
Dim boo As Boolean

  For r = FlexGrid.Rows - 1 To 1 Step -1
    boo = False
         For c = 1 To FlexGrid.Cols - 1
             If InStr(1, FlexGrid.TextMatrix(r, c), target_name, vbTextCompare) Then

         boo = True
         Exit For
       End If
       Next c
     If boo = False Then FlexGrid.RemoveItem (r)

  Next r
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

For one thing, if you're gonna LCASE$ the target_name, you need to LCASE$ the contents of the FlexGrid too. Change your Instr line to:
If Instr(LCase$(FlexGrid.TextMatrix(r, c)), target_name, vbTextCompare) Then
For another, as you can in my example line, you don't need the first parameter (the "1") in the InStr statement, as starting the search from the first character is the default.
Lastly, the statement:
For r = FlexGrid.Rows - 1 To 1 Step -1
can get flaky sometimes when you're deleting rows and each iteration of the loop must recalculate. Better to use:
   r = FlexGrid.Rows -1
   If r >= 1 Then
      'do your code here, using Exit Do rather than Exit Loop upon success
   End If
Oops, I meant:
'do your code here, using Exit Do rather than Exit For upon success
Sheesh, I keep forgetting stuff, sorry. Column numbers start at 0, so unless you KNOW you'll never find a match in the first column, change:
For c = 1 To FlexGrid.Cols - 1
For c = 0 To FlexGrid.Cols - 1

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
IntelopsAuthor Commented:
Can you explain bit more please
What do you need further explanation on?
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.