[RESOLVED] Find, Find Next, Replace!
I desperately need your help now :cry:
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. :blush:
Re: Find, Find Next, Replace!
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 ?
Let's take care of this one first.
s = Replace("ABCdefGHI", "cdef", "????", , , vbTextCompare)
Re: Find, Find Next, Replace!
Now for the other
Code:
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
Re: Find, Find Next, Replace!
I find this:
Code:
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
Re: Find, Find Next, Replace!
Ummm....it doesn't allow for upper/lower case which is what he wanted
1 Attachment(s)
Re: Find, Find Next, Replace!
Here is a zip file for a very simple project
Re: Find, Find Next, Replace!
AWESOME! You're by far one of the greatest members :D
THANK YOU VERY MUCH!
1 Attachment(s)
Re: Find, Find Next, Replace!
Here's the Find, Find Next, and Replace project
NOTE:
I didn't use the Replace command in this example but you can subsistute it instead of what I did use
Re: Find, Find Next, Replace!
Fantastic! Thread Resolved ^^