I want to be able to find a specific text inside a RichTextBox and then if the text is found then it pops a message box out. i tried many different ways but still cant do it. please help me
Printable View
I want to be able to find a specific text inside a RichTextBox and then if the text is found then it pops a message box out. i tried many different ways but still cant do it. please help me
Use the RichTextBox's Find property.
Or you can use the Instr function.Code:RichTextBox1.Find "MyText"
RichTextBox1.SetFocus
Code:If Instr(RichTextBox1.Text, "MyText") Then
Msgbox "Text found!"
Else
Msgbox "Text not found!"
End If
thanx. that works perfectly
If you are using the first one, as you wanted a message box:
Code:RichTextBox1.Find "MyText"
RichTextBox1.SetFocus
If RichTextBox1.SelText <> "" Then
MsgBox "Text found!"
Else
MsgBox "Text not found!"
End If
InStr can return the position of it as well.
Code:nPosition = InStr(RTF1, "MyText")
If the purpose is just to find it, not specify it's position you can do it faster with like operator:
Code:If RichTextBox1.Text, "*MyText*") Then
Msgbox "Text found!"
Else
Msgbox "Text not found!"
End If
Your code is somewhat faulty, Kedaman.
Code:If RichTextBox1.Text Like "*MyText*" Then
MsgBox "Text found!"
Else
MsgBox "Text not found!"
End If
Ooops! Too tired maybe?