Results 1 to 9 of 9

Thread: [RESOLVED] Find, Find Next, Replace!

  1. #1

    Thread Starter
    Member Black Wolf's Avatar
    Join Date
    Apr 2006
    Location
    Visual Basic
    Posts
    61

    Resolved [RESOLVED] Find, Find Next, Replace!

    I desperately need your help now

    I have a TextBox and I was wondering if I could make a small "Find" option to search for texts within my textbox and "Find Next" option too..Is this possible ? How ?

    Another question, I am using the code Replace to replace but its not working very well when it comes to upper cases and lower cases..what must I do ?

    Thanks in advance.
    Always New I Never Belonged In This World .. I Wasn't Made For This
    But I'LL Never Forget Those Who Betrayed Me .... And Those Who Never Failed My Trust.

    Visual Basic 6.0 : The Choice of The Professional

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Find, Find Next, Replace!

    Another question, I am using the code Replace to replace but its not working very well when it comes to upper cases and lower cases..what must I do ?

    Let's take care of this one first.

    s = Replace("ABCdefGHI", "cdef", "????", , , vbTextCompare)

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Find, Find Next, Replace!

    Now for the other
    Code:
    Dim SearchStart As Integer
     '
     '
    Private Sub Form_Load()
     txtMessage.Text = "qwerABcdrtyuoabcdIUYAbcDoipo"
     SearchStart = 1
     Command1.Caption = "Find"
    End Sub 
    
    Private Sub Command1_Click()
     Search
    End Sub
    
    Private Sub Search()
     q1 = InStr(SearchStart, txtMessage.Text, "abcd", vbTextCompare) '<----
     If q1 > 0 Then
       Command1.Caption = "Find Next"
       txtMessage.SelStart = q1 - 1
       txtMessage.SelLength = 4
       txtMessage.SetFocus
       SearchStart = q1 + 1
     Else
       Command1.Caption = "Find"
       SearchStart = 1
       MsgBox "Not found"
    
     End If  '
    End Sub
    EDIT

    Corrected misspelled word
    Last edited by jmsrickland; Feb 13th, 2008 at 12:44 PM.

  4. #4
    Addicted Member
    Join Date
    Jan 2007
    Location
    Iran
    Posts
    237

    Re: Find, Find Next, Replace!

    I find this:

    Code:
    Private TargetPosition As Integer
    
    Public Sub FindText(ByVal start_at As Integer)
    
    Dim pos As Integer
    Dim target As String
    
    target = txtTarget.Text
    pos = InStr(start_at, txtBody.Text, target)
    
    If pos > 0 Then
    TargetPosition = pos
    txtBody.SelStart = TargetPosition - 1
    txtBody.SelLength = Len(target)
    txtBody.SetFocus
    Else
    MsgBox "Not found!"
    txtBody.SetFocus
    End If
    
    End Sub
    
    Private Sub cmdFind_Click()
    FindText 1
    End Sub
    
    Private Sub cmdFindNext_Click()
    FindText TargetPosition + 1
    End Sub
    Y.P.Y

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Find, Find Next, Replace!

    Ummm....it doesn't allow for upper/lower case which is what he wanted
    Last edited by jmsrickland; Feb 13th, 2008 at 12:57 PM.

  6. #6
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Find, Find Next, Replace!

    Here is a zip file for a very simple project
    Attached Files Attached Files

  7. #7

    Thread Starter
    Member Black Wolf's Avatar
    Join Date
    Apr 2006
    Location
    Visual Basic
    Posts
    61

    Re: Find, Find Next, Replace!

    AWESOME! You're by far one of the greatest members

    THANK YOU VERY MUCH!
    Always New I Never Belonged In This World .. I Wasn't Made For This
    But I'LL Never Forget Those Who Betrayed Me .... And Those Who Never Failed My Trust.

    Visual Basic 6.0 : The Choice of The Professional

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Find, Find Next, Replace!

    Here's the Find, Find Next, and Replace project


    NOTE:

    I didn't use the Replace command in this example but you can subsistute it instead of what I did use
    Attached Files Attached Files

  9. #9

    Thread Starter
    Member Black Wolf's Avatar
    Join Date
    Apr 2006
    Location
    Visual Basic
    Posts
    61

    Re: Find, Find Next, Replace!

    Fantastic! Thread Resolved ^^
    Always New I Never Belonged In This World .. I Wasn't Made For This
    But I'LL Never Forget Those Who Betrayed Me .... And Those Who Never Failed My Trust.

    Visual Basic 6.0 : The Choice of The Professional

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width