I was originally using this code.
Dim selectedTextStart As Integer selectedTextStart = InStr(form1.RichTextBox.Text, textToFind.Text) If selectedTextStart = 0 Then MessageBox.Show("Show some warning text") Exit Sub End If form1.RichTextBox.Select(selectedTextStart - 1, textToFind.Text.Length) form1.RichTextBox.ScrollToCaret()
I was informed by a user on dreamincode that I should scrap the InStr function and instead use something like this:
Dim lastPosition As Integer = 0 lastPosition = richTextBox.Find(textToFind, lastPosition, form1.MatchCase) 'MatchCase or whatever search you do) last position = last position + 1
The above code worked fine to some extent. However I then realised it was missing some functionality such as:
How do I allow the user to only perform the 'Find and Replace' on only some text that they selected?
How do I allow the user to change the starting position of the 'Find and Replace'? In other words, once they click the Find button and the first instance has happened, what if they want to move the cursor back to the beginning... how would the code enable them to move the cursor?
Would be much help if you could assist me.