Advertisement
2002ASP String Manipulation #406

Find and Highlight Substring

' Given an editable textbox named Text1, this code prompts to find a word and ' searches throught the textbox and highlights the first occurance of the ' found word (if exists).

AI

AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Source Code
original-source
Private Sub FindFunction_Click()
Rem Find/highlight first occurance of a word in a textbox named Text1 
Dim a As String
Dim y As Integer
a = InputBox("Find text: ", "Find", "")
Call Text1.SetFocus
SendKeys ("^{HOME}")
y = 1
Do Until y = Len(Text1.text)
 Rem check if word was located
 If Mid(UCase$(Text1.text), y, Len(a)) = UCase$(a) Then
   Rem highlight the found word and exit sub
   For x = 1 To Len(a)
    SendKeys ("+{RIGHT}")
   Next x
   Exit Do
 End If
 Rem do nothing if carriage return encountered else highlight found word
 If Mid(Text1.text, y, 1) = Chr$(13) Then
 Else
 Rem move the cursor to the next element of text
 SendKeys ("{RIGHT}")
 End If
 y = y + 1
 If y > Len(Text1.text) Then Exit Do
Loop
End Sub
Original Comments (3)
Recovered from Wayback Machine