SETHA SITE INFORMATION

  • Increase font size
  • Default font size
  • Decrease font size

Find and Replace text in Multiline TextBox Control in Visual Basic 6

E-mail Print PDF

This article shows you how to Find, Find Next and Replace text (including Case Sensitive option) in multiple line TextBox Control in Visual Basic 6. After you click button Find you will see InputBox to enter text you wish to find in TextBox. Then you can click button Find Next or button Replace. The below code is the sub procedure use to Find and Find Next the text in TextBox (txtContent).

Private Sub cmdFindNext_Click()
    txtContent.SetFocus
    If chkCase.Value = 1 Then
        FindText = InStr(PostFind, LCase(txtContent), LCase(TextToFind))
    Else
        FindText = InStr(PostFind, txtContent, TextToFind)
    End If
    If FindText > 0 Then
        txtContent.SelStart = FindText - 1
        txtContent.SelLength = Len(TextToFind)
        cmdReplace.Enabled = True
        PostFind = FindText + 1
    Else
        MsgBox "No text '" & TextToFind & "' any more.", vbExclamation, "Info..."
    End If
End Sub
Download Source Code
 
1) 1st Form

 
2) Text to Find

 
3) Result