I have a TextBox and I was wondering if I could make a small "Find" option to search for texts within my textbox and "Find Next" option too..Is this possible ? How ?
Another question, I am using the code Replace to replace but its not working very well when it comes to upper cases and lower cases..what must I do ?
Thanks in advance.
Always New I Never Belonged In This World .. I Wasn't Made For This
But I'LL Never Forget Those Who Betrayed Me .... And Those Who Never Failed My Trust.
Dim SearchStart As Integer
'
'
Private Sub Form_Load()
txtMessage.Text = "qwerABcdrtyuoabcdIUYAbcDoipo"
SearchStart = 1
Command1.Caption = "Find"
End Sub
Private Sub Command1_Click()
Search
End Sub
Private Sub Search()
q1 = InStr(SearchStart, txtMessage.Text, "abcd", vbTextCompare) '<----
If q1 > 0 Then
Command1.Caption = "Find Next"
txtMessage.SelStart = q1 - 1
txtMessage.SelLength = 4
txtMessage.SetFocus
SearchStart = q1 + 1
Else
Command1.Caption = "Find"
SearchStart = 1
MsgBox "Not found"
End If '
End Sub
EDIT
Corrected misspelled word
Last edited by jmsrickland; Feb 13th, 2008 at 12:44 PM.
Private TargetPosition As Integer
Public Sub FindText(ByVal start_at As Integer)
Dim pos As Integer
Dim target As String
target = txtTarget.Text
pos = InStr(start_at, txtBody.Text, target)
If pos > 0 Then
TargetPosition = pos
txtBody.SelStart = TargetPosition - 1
txtBody.SelLength = Len(target)
txtBody.SetFocus
Else
MsgBox "Not found!"
txtBody.SetFocus
End If
End Sub
Private Sub cmdFind_Click()
FindText 1
End Sub
Private Sub cmdFindNext_Click()
FindText TargetPosition + 1
End Sub
AWESOME! You're by far one of the greatest members
THANK YOU VERY MUCH!
Always New I Never Belonged In This World .. I Wasn't Made For This
But I'LL Never Forget Those Who Betrayed Me .... And Those Who Never Failed My Trust.
Always New I Never Belonged In This World .. I Wasn't Made For This
But I'LL Never Forget Those Who Betrayed Me .... And Those Who Never Failed My Trust.