Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to detect string pattern inside textbox ?

Status
Not open for further replies.

davidck88

Programmer
Jan 5, 2009
27
NL
Hi all i am checking the content of textbox against a listbox items as shown in the following code. But i want to improve this code so not only it detects the exact matches but also if any part of words from listbox is found in textbox then command6 is triggred as well .

For example i got word tony in the listbox. If the content of text2 is some thing like tony ck ,you are tony , tony is good dude...it also detect those patterns and call the command6 buton. I be happy if some one show me how i can make such compare.Looking forward for reply.Thanks
Code:
For au = 0 To Form1.List1.ListCount - 1
        If Form1.List1.list(au) = Text2 Then
           
            Command6_Click ' this will send warning
            
End If
 

How about:
Code:
For au = 0 To Form1.List1.ListCount - 1
    If [blue]InStr(1, Form1.List1.list(au), Text2.Text)[/blue] Then
        Command6[blue].Value = True[/blue]
    End If
Next au

Have fun.

---- Andy
 

Oooops, don't forget:
Code:
For au = 0 To Form1.List1.ListCount - 1
    If InStr(1, Form1.List1.list(au), Text2.Text) Then
        Command6.Value = True
        [red]Exit For[/red]
    End If
Next au

Have fun.

---- Andy
 
You might want to start by checking out the [tt]Like[/tt] operator
 
Andrzejek thanks for your reply .your code only covers when the content of text is ONLY tony as the one in listbox!! SO your code is same as my orginal code. What i want to detect are the following cases from textbox content :

Listbox words to look for:tony,TONY,Tony,t-o-n-y,T-O-N-Y,tony_,....

Textbox content examples:
1)i want to meet tony
2)i want to meet TONY
3)i want to meet Tony
4)i want to meet t-o-n-y
5)i want to meet T-O-N-Y
6)i want to meet tony_

So what i want a solution that if any of the listbox words found in textbox just like example given above then the function get triggered. I hope some one help me achive this goal.Thanks
 
I assume that you do not want Antony or Stony also.

If you do not want either of the above my suggestion would be to compare using Ucase on both sides of the equal signs. i.e with the listbox elements as well as with user input
 
Use
Code:
Option Compare Text
to globally eliminate case-sensitive comparisons.

You might also want to look into regular expressions for your more complicated requirements. (Search this forum.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top