by Silambarasan (1 Submission)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Wed 26th April 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code helps to search the text as like you're using ctrl+F
API Declarations
'declarations in the code itself
'Textbox - Quantity 1
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
If vbCtrlMask And KeyCode = 70 Then
Form2.Show vbModeless, Me
End If
End Sub
'Form2 codings
'Text1 - Text to be find
'Text2 - Text to be replace
'command1 - Find Next
'command2 - Replace
'command3 - cancel
'command4 - Replace all
Dim length As Integer
Dim start As Integer
Dim str As Integer
Dim benabled As Boolean
Private Sub Command1_Click()
benabled = True
length = InStr(start, Form1.Text1.Text, Text1.Text)
If length > 0 Then
Form1.Text1.SelStart = length - 1
Form1.Text1.SelLength = Len(Text1.Text)
Else
MsgBox "The Specific Region has been searched", vbInformation
Exit Sub
End If
start = length + Len(Text1.Text)
End Sub
Private Sub Command2_Click()
If benabled = False Then
Command1.Value = -1
Exit Sub
End If
If start > str Then
Form1.Text1.SelText = Text2.Text
str = start
End If
Call Command1_Click
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Command4_Click()
start = 1
here:
If benabled = False Then
Command1.Value = -1
Exit Sub
End If
length = InStr(start, Form1.Text1.Text, Text1.Text)
If length > 0 Then
Form1.Text1.SelStart = length - 1
Form1.Text1.SelLength = Len(Text1.Text)
Else
MsgBox "The Specific Region has been searched", vbInformation
Exit Sub
End If
start = length + Len(Text1.Text)
Form1.Text1.SelText = Text2.Text
GoTo here
End Sub
Private Sub Form_Load()
length = 1
start = 1
str = 1
benabled = False
End Sub
Private Sub Text1_Change()
Call Form_Load
End Sub