Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Posted

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)???

  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]
Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...