text editor in vb 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mygirl22
    New Member
    • Feb 2009
    • 20

    text editor in vb 2005

    Hi,
    I wanted to know how to add a replace method to a text editor (notepad) to search for a word and replace it
    1. say in (notepad) you type something in the textbox1-------"me"
    2. then am suppose to type "me" in text box 2---and
    3. click the find button and it suppose to find the text in textbox1
    4. then you type in textbox3---- "us" and
    5. click the replace button and it replaces "me" with "us"

    how do i do this?
  • thoffman
    New Member
    • Apr 2009
    • 5

    #2
    mygirl22... That would be Ctrl+H in both notepad and VB 2005 Express... It's also located under the "Edit" menu... "Find and replace"

    Comment

    • aryanbs
      New Member
      • Mar 2009
      • 42

      #3
      Hi mygirl22 (oops sorry)
      You do post in MSDN social forum too, right?

      Ok to find the text..do following, suppose you are finding text from textbox2

      Code:
      TextBox1.HideSelection = False 'can be set once in design time
             
               TextBox1.SelectionStart = TextBox1.Text.IndexOf(TextBox2.Text, StringComparison.OrdinalIgnoreCase)
              TextBox1.SelectionLength = TextBox2.Text.Length
      Now to replace,
      Since you have already highlighted the found text, just do

      Code:
       If TextBox1.SelectedText.Length > 0 Then
                  TextBox1.SelectedText = TextBox3.Text
              End If

      Comment

      • mygirl22
        New Member
        • Feb 2009
        • 20

        #4
        thanks, i appreciate it..

        Comment

        • mygirl22
          New Member
          • Feb 2009
          • 20

          #5
          ok i did the find method but i have a problem..it also needs to act as a "find next"...meaning that
          1.when i click the find button,
          2.in the main form, it should find the text
          3. and when i click it again
          4. it should find the same text again ..if it's in the main form

          i can't figure out how to write the loop..plz help...
          this is what i have so far
          Code:
           Private Sub xFindButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xFindButton.Click
          
                  Dim startPos As Integer
                  startPos = xTxtSourceTextBox.Text.IndexOf(Me.xFindTextBox.Text) ', type)
                  If startPos = 0 Then
                      Me.xTxtSourceTextBox.Focus()
                 
                       End If
                  If startPos < 0 Then
                      MessageBox.Show("The String '" + xFindTextBox.Text + _
                      "' could not be found", "Text Not Found", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                      Return
                  End If
                  Me.xTxtSourceTextBox.Focus()
                  xTxtSourceTextBox.Select(startPos, xFindTextBox.Text.Length)
                  xTxtSourceTextBox.ScrollToCaret()

          Comment

          Working...