FIND AND REPLACE IN TEXTBOX

TO DO SO YOU WILL NEED TO CREATE NEW  RICHTEXTBOX CONTROL

Follow The Steps :
Right Click on your Project ; GO TO Add> And Select CLASS


Now Insert The following Code

  Inherits RichTextBox
 
 
    Public Sub Replace(ByVal FindText As String, ByVal ReplaceText As String)
        Me.Find(FindText)
        If Not Me.SelectionLength = 0 Then
            Me.SelectedText = ReplaceText
        Else
            ' MsgBox("The following specified text was not found: " & FindText)
        End If
    End Sub
 
 
    Public Sub Replace(ByVal FindText As String, ByVal ReplaceText As String, ByVal ReplaceAll As Boolean, _
     ByVal MatchCase As Boolean, ByVal WholeWord As Boolean)
 
        Select Case ReplaceAll
 
            Case False
                If MatchCase = True Then
                    If WholeWord = True Then
                        Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord)
                    Else
                        Me.Find(FindText, RichTextBoxFinds.MatchCase)
                    End If
                Else
                    If WholeWord = True Then
                        Me.Find(FindText, RichTextBoxFinds.WholeWord)
                    Else
                        Me.Find(FindText)
                    End If
                End If
 
                If Not Me.SelectionLength = 0 Then
                    Me.SelectedText = ReplaceText
                Else
                    '  MsgBox("The following specified text was not found: " & FindText)
                End If
 
 
            Case True
 
 
                Dim i As Integer
                For i = 0 To Me.TextLength
 
 
                    If MatchCase = True Then
                        If WholeWord = True Then
                            Me.Find(FindText, RichTextBoxFinds.MatchCase Or RichTextBoxFinds.WholeWord)
                        Else
                            Me.Find(FindText, RichTextBoxFinds.MatchCase)
                        End If
                    Else
                        If WholeWord = True Then
                            Me.Find(FindText, RichTextBoxFinds.WholeWord)
                        Else
                            Me.Find(FindText)
                        End If
                    End If
 
 
                    If Not Me.SelectionLength = 0 Then
                        Me.SelectedText = ReplaceText
                    Else
                        ' MsgBox(i & " occurrence(s) replaced")
                        Exit For
                    End If
                Next i
 
        End Select
End Sub 

Now Go to Debug And Build


Goto your main Form And U Will See a New Controll -





  

Add The Following Code to Replace

Me.RichtextboxFr1.replace(text to be finded , text to replace with, replace all as boolean , machcase as boolean , wholeword as boolean)

0 comments:

Note: only a member of this blog may post a comment.

Translate