The for each loop may not be ideal for strings which are a series of characters ...
But you can do something like:
Code:
Private Sub Button1_Click (ByVal sender As System. Object, ByVal e As System. EventArgs) Handles Button1. Click
Dim TextBoxWitness As New TextBox
TextBoxWitness. Text = TextBox5. Text
Dim searchmot As String
Dim PosMot As Integer
Dim numIndex = 0
Dim counter = 0
searchmot = TextBox1. Text
PosMot = InStr (TextBoxWitness.Text.ToLower, TextBox1.Text.ToLower)
For Each character In TextBoxWitness.Text
If PosMot <> 0 Then
counter = 1
'PosMot from 1 to Len (Text1.Text), while SelStart ranges from 0 to Len (Text1.Text) -1
'We must therefore remove 1
numIndex = TextBoxWitness.Text.indexOf (searchmot)
TextBoxWitness. Text = TextBoxWitness.Text.Remove (numIndex, searchmot.Length)
PosMot = InStr (TextBoxWitness.Text.ToLower, searchmot.ToLower)
TextBox5.SelectionStart = PosMot 'set cursor position
TextBox5.SelectionLength = Len (searchmot) 'defined length highlight
TextBox5.Focus () "gives the focus to the box text1
Else
If counter = 0 Then
MsgBox ( "Unknown Client")
Exit For
End If
End If
Next
End Sub
Bookmarks