www.pudn.com > Super_richBoxall.zip > frmFindReplace.frm
VERSION 5.00
Begin VB.Form frmFindReplace
BorderStyle = 3 'Fixed Dialog
Caption = "Find and Replace"
ClientHeight = 2085
ClientLeft = 3840
ClientTop = 3945
ClientWidth = 6480
BeginProperty Font
Name = "Tahoma"
Size = 8.25
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Icon = "frmFindReplace.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2085
ScaleWidth = 6480
ShowInTaskbar = 0 'False
Begin VB.CheckBox chkOption
Caption = "Find in Se&lection Only"
Height = 255
Index = 2
Left = 1140
TabIndex = 10
Top = 1560
Width = 2115
End
Begin VB.CheckBox chkOption
Caption = "Find &Whole Words Only"
Height = 255
Index = 1
Left = 1140
TabIndex = 9
Top = 1320
Width = 2115
End
Begin VB.CheckBox chkOption
Caption = "Matc&h Case"
Height = 255
Index = 0
Left = 1140
TabIndex = 8
Top = 1080
Width = 2115
End
Begin VB.ComboBox cboReplaceWith
Height = 315
Left = 1140
TabIndex = 7
Top = 540
Width = 3735
End
Begin VB.CommandButton cmdReplaceAll
Caption = "Replace &All"
Height = 375
Left = 5040
TabIndex = 5
Top = 1500
Width = 1335
End
Begin VB.CommandButton cmdReplace
Caption = "&Replace"
Height = 375
Left = 5040
TabIndex = 4
Top = 1080
Width = 1335
End
Begin VB.CommandButton cmdCancel
Cancel = -1 'True
Caption = "Cancel"
Height = 375
Left = 5040
TabIndex = 3
Top = 540
Width = 1335
End
Begin VB.CommandButton cmdFindNext
Caption = "&Find Next"
Default = -1 'True
Height = 375
Left = 5040
TabIndex = 2
Top = 120
Width = 1335
End
Begin VB.ComboBox cboFindWhat
Height = 315
Left = 1140
TabIndex = 1
Top = 180
Width = 3735
End
Begin VB.Label lblReplace
Caption = "Replace wi&th:"
Height = 255
Left = 120
TabIndex = 6
Top = 600
Width = 1275
End
Begin VB.Label lblFindWhat
Caption = "Fi&nd what:"
Height = 255
Left = 120
TabIndex = 0
Top = 240
Width = 1275
End
End
Attribute VB_Name = "frmFindReplace"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Public Event DoFind(ByVal sWhat As String, ByVal eOptions As ERECFindTypeOptions, ByVal bFindNext As Boolean, ByVal bSelection As Boolean)
Public Event DoReplace(ByVal sWhat As String, ByVal sWith As String, ByVal eOptions As ERECFindTypeOptions, ByVal bFindNext As Boolean, ByVal bSelection As Boolean, ByVal bReplaceAll As Boolean)
Private m_sFindHistory() As String
Private m_iFindHistoryCount As Long
Private m_sReplaceHistory() As String
Private m_iReplaceHistoryCount As Long
Private m_iMaxHistorySize As Long
Private m_sFindWhat As String
Private m_sReplaceWith As String
Private m_bMatchCase As Boolean
Private m_bWholeWord As Boolean
Private m_bSelection As Boolean
Public Enum EFRModeConstants
efrFind = 0
efrReplace = 1
End Enum
Private m_eMode As EFRModeConstants
Private m_bLoaded As Boolean
Public Property Let Mode(ByVal eMode As EFRModeConstants)
m_eMode = eMode
If (m_bLoaded) Then
If (eMode = efrFind) Then
cmdReplace.Caption = "&Replace..."
Else
cmdReplace.Caption = "&Replace"
End If
lblReplace.Visible = (eMode = efrReplace)
cboReplaceWith.Visible = (eMode = efrReplace)
cmdReplaceAll.Visible = (eMode = efrReplace)
End If
End Property
Public Property Get Mode() As EFRModeConstants
Mode = m_eMode
End Property
Public Property Let MaxHistorySize(ByVal lSize As Long)
m_iMaxHistorySize = lSize
End Property
Public Property Get MaxHistorySize() As Long
MaxHistorySize = m_iMaxHistorySize
End Property
Public Property Get FindHistoryCount() As Long
FindHistoryCount = m_iFindHistoryCount
End Property
Public Property Get FindHistory(ByVal lIndex As Long) As String
FindHistory = m_sFindHistory(lIndex)
End Property
Public Sub AddFindHistory(ByVal sText As String)
Dim i As Long
Dim sCurrent As String
pAddHistory sText, m_sFindHistory(), m_iFindHistoryCount
sCurrent = cboFindWhat.Text
If (m_bLoaded) Then
cboFindWhat.Clear
For i = 1 To m_iFindHistoryCount
cboFindWhat.AddItem m_sFindHistory(i)
Next i
cboFindWhat.Text = sCurrent
End If
End Sub
Public Sub AddReplaceHistory(ByVal sText As String)
Dim i As Long
Dim sCurrent As String
pAddHistory sText, m_sReplaceHistory(), m_iReplaceHistoryCount
If (m_bLoaded) Then
cboReplaceWith.Clear
For i = 1 To m_iReplaceHistoryCount
cboReplaceWith.AddItem m_sReplaceHistory(i)
Next i
cboReplaceWith.Text = sCurrent
End If
End Sub
Public Property Let FindWhat(ByVal sText As String)
m_sFindWhat = sText
If (m_bLoaded) Then
cboFindWhat.Text = sText
End If
End Property
Public Property Let ReplaceWith(ByVal sText As String)
m_sReplaceWith = sText
If (m_bLoaded) Then
cboReplaceWith.Text = sText
End If
End Property
Private Sub pAddHistory( _
ByVal sText As String, _
ByRef sHistory() As String, _
ByRef iCount As Long _
)
Dim i As Long
Dim iFound As Long
Dim iMax As Long
' Check if already there:
For i = 1 To iCount
If (sHistory(i) = sText) Then
iFound = i
Exit For
End If
Next i
' Add this item as required:
If (iFound) Then
' Swap iFound & 1:
If (iFound <> 1) Then
sHistory(iFound) = sHistory(1)
sHistory(1) = sText
End If
Else
' Move all down and insert at 1:
iMax = iCount + 1
If (iMax > m_iMaxHistorySize) Then
iMax = m_iMaxHistorySize
End If
If (iMax > iCount) Then
iCount = iCount + 1
ReDim Preserve sHistory(1 To iCount) As String
End If
For i = iMax To 2 Step -1
sHistory(i) = sHistory(i - 1)
Next i
sHistory(1) = sText
End If
End Sub
Public Property Get MatchCase() As Boolean
MatchCase = m_bMatchCase
End Property
Public Property Let MatchCase(ByVal bState As Boolean)
m_bMatchCase = bState
If (m_bLoaded) Then
chkOption(0).Value = Abs(bState)
End If
End Property
Public Property Get WholeWord() As Boolean
WholeWord = m_bWholeWord
End Property
Public Property Let WholeWord(ByVal bState As Boolean)
m_bWholeWord = bState
If (m_bLoaded) Then
chkOption(1).Value = Abs(bState)
End If
End Property
Public Property Get SelectionOnly() As Boolean
SelectionOnly = m_bSelection
End Property
Public Property Let SelectionOnly(ByVal bState As Boolean)
m_bSelection = bState
If (m_bLoaded) Then
chkOption(2).Value = Abs(bState)
End If
End Property
Private Sub chkOption_Click(Index As Integer)
Select Case Index
Case 0
m_bMatchCase = (chkOption(Index).Value = Checked)
Case 1
m_bWholeWord = (chkOption(Index).Value = Checked)
Case 2
m_bSelection = (chkOption(Index).Value = Checked)
End Select
End Sub
Private Sub cmdCancel_Click()
Me.Hide
End Sub
Private Sub cmdFindNext_Click()
Dim eOption As ERECFindTypeOptions
eOption = peGetOption()
RaiseEvent DoFind(cboFindWhat.Text, eOption, True, m_bSelection)
End Sub
Private Sub cmdReplace_Click()
Dim eOption As ERECFindTypeOptions
eOption = peGetOption()
RaiseEvent DoReplace(cboFindWhat.Text, cboReplaceWith.Text, eOption, True, m_bSelection, False)
End Sub
Private Sub cmdReplaceAll_Click()
Dim eOption As ERECFindTypeOptions
eOption = peGetOption()
RaiseEvent DoReplace(cboFindWhat.Text, cboReplaceWith.Text, eOption, True, m_bSelection, True)
End Sub
Private Function peGetOption() As ERECFindTypeOptions
Dim eOption As ERECFindTypeOptions
eOption = FR_DOWN
eOption = eOption Or (Abs(m_bMatchCase) * FR_MATCHCASE)
eOption = eOption Or (Abs(m_bWholeWord) * FR_WHOLEWORD)
peGetOption = eOption
End Function
Private Sub Form_Initialize()
m_iMaxHistorySize = 5
End Sub
Private Sub Form_Load()
Dim i As Long
' Add History items:
For i = 1 To m_iFindHistoryCount
cboFindWhat.AddItem m_sFindHistory(i)
Next i
FindWhat = m_sFindWhat
For i = 1 To m_iReplaceHistoryCount
cboReplaceWith.AddItem m_sReplaceHistory(i)
Next i
ReplaceWith = m_sReplaceWith
chkOption(0).Value = Abs(m_bMatchCase)
chkOption(1).Value = Abs(m_bWholeWord)
chkOption(2).Value = Abs(m_bSelection)
m_bLoaded = True
Mode = m_eMode
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
If (UnloadMode = vbFormControlMenu) Then
' Don't unload except in VB code.
Cancel = True
Me.Hide
End If
End Sub