by silverx10 (5 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (3 Votes)
This source code will search for a certain string from a TextBox (can be modified to search from any string-bearing control, etc.). Once the string is found, a message box will appear letting you know that the string was found, and then the string will be highlighted.
Assumes
1) Start a new Standard EXE project.
2) Add two (2) TextBox controls to the Form.
3) Erase the contents of the TextBox controls. Alternately, you can set Text2's Multiline property to True, as it is going to be the TextBox to search for the string in.
4) Add one (1) CommandButton control to the Form.
5) Set the CommandButton Caption property to "&Search"
6) Click the View Code button; copy and paste the source code below.
7) Run the application.
8) Visit my website! http://www.matnet.com/~pyrosoft
'Text2 is the TextBox to search for the string in.
Dim I as Integer
Private Sub Command1_Click()
For I = 1 To Len(Text2)
If Mid(Text2, I, Len(Text1)) = Text1 Then
MsgBox "String located and highlighted."
Text2.SetFocus
Text2.SelStart = I - 1
Text2.SelLength = Len(Text1)
End If
Next I
End Sub()