BrettW Posted January 21, 2010 Posted January 21, 2010 Hi all. I'm trying to find text in richtextbox like so: RichTextBox1.Find("Hello") Which works but it doesn't find the next occurrence of 'Hello'. (Find Next) Can anyone help me? Quote
Administrators PlausiblyDamp Posted January 21, 2010 Administrators Posted January 21, 2010 One of the overloads allows you to specify where to search from, you can start from where the last occurrence was found using that parameter. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
BrettW Posted January 21, 2010 Author Posted January 21, 2010 I am trying to get the starting point of the selection and then add 1 to it and search from there like this: dim start as integer start = Form1.RichTextBox1.SelectionStart start = start + 1 MsgBox(start) Try Form1.RichTextBox1.Find(TextBox1.Text, start, RichTextBoxFinds.None) Catch ex As Exception MsgBox("The text was not found", MsgBoxStyle.Information, "VBS Create") End Try But it won't add 1 to start it just adds it to the end (1 + 1 = 11)??? Quote
Leaders snarfblam Posted January 21, 2010 Leaders Posted January 21, 2010 Did you copy and paste that code? Because from what I can see you have (integer) = (integer) + (integer), and there is no reason that it should be treated like a string. If you are using a string constant for your "1" or start is declared as an object or string, then this behavior might make sense. Quote [sIGPIC]e[/sIGPIC]
BrettW Posted January 22, 2010 Author Posted January 22, 2010 No i didn't copy and paste it. There is absolutely no explanation for this strange behaviour. Perhaps there is a bug in VB. But is normally works?!??!?!?! I will experiment to try and get it to work. Quote
BrettW Posted January 22, 2010 Author Posted January 22, 2010 The integer problem is fixed now but i have another problem: Public Class ReplaceStr Dim start As Integer Dim first As Boolean = True Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click start = Form1.TextBox1.SelectionStart Try Form1.TextBox1.Find(TextBox1.Text, start, RichTextBoxFinds.None) Form1.TextBox1.Focus() If first = False Then start = start + 1 End If first = False Catch ex As Exception MsgBox("The text was not found", MsgBoxStyle.Information, "VBS Create") End Try End Sub End Class This is not working to find the next occurence of a word. Can someone pls help. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.