Find text in RichTextBox

BrettW

Freshman
Joined
Nov 12, 2009
Messages
35
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?
 
I am trying to get the starting point of the selection and then add 1 to it and search from there like this:

Code:
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)???
 
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.
 
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.
 
The integer problem is fixed now but i have another problem:

Code:
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.
 
Back
Top