FindReplaceScr.frm

 VERSION 5.00
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "TABCTL32.OCX"
Begin VB.Form FindReplaceScr
   BorderStyle     =   3  'Fixed Dialog
   Caption         =   "Find and Replace"
   ClientHeight    =   3015
   ClientLeft      =   2760
   ClientTop       =   3750
   ClientWidth     =   7695
   ControlBox      =   0   'False
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3015
   ScaleWidth      =   7695
   ShowInTaskbar   =   0   'False
   Begin TabDlg.SSTab Tabs
      Height          =   2775
      Left            =   120
      TabIndex        =   2
      Top             =   120
      Width           =   7455
      _ExtentX        =   13150
      _ExtentY        =   4895
      _Version        =   393216
      Style           =   1
      Tabs            =   2
      TabHeight       =   520
      ShowFocusRect   =   0   'False
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      TabCaption(0)   =   "Fin&d"
      TabPicture(0)   =   "FindReplaceScr.frx":0000
      Tab(0).ControlEnabled=   -1  'True
      Tab(0).Control(0)=   "Label1"
      Tab(0).Control(0).Enabled=   0   'False
      Tab(0).Control(1)=   "Label2"
      Tab(0).Control(1).Enabled=   0   'False
      Tab(0).Control(2)=   "Line1"
      Tab(0).Control(2).Enabled=   0   'False
      Tab(0).Control(3)=   "Line2"
      Tab(0).Control(3).Enabled=   0   'False
      Tab(0).Control(4)=   "Search(0)"
      Tab(0).Control(4).Enabled=   0   'False
      Tab(0).Control(5)=   "CloseButt(0)"
      Tab(0).Control(5).Enabled=   0   'False
      Tab(0).Control(6)=   "FindButt"
      Tab(0).Control(6).Enabled=   0   'False
      Tab(0).Control(7)=   "MatchCase(0)"
      Tab(0).Control(7).Enabled=   0   'False
      Tab(0).Control(8)=   "WholeWord(0)"
      Tab(0).Control(8).Enabled=   0   'False
      Tab(0).ControlCount=   9
      TabCaption(1)   =   "Re&place"
      TabPicture(1)   =   "FindReplaceScr.frx":001C
      Tab(1).ControlEnabled=   0   'False
      Tab(1).Control(0)=   "Label3"
      Tab(1).Control(0).Enabled=   0   'False
      Tab(1).Control(1)=   "Label4"
      Tab(1).Control(1).Enabled=   0   'False
      Tab(1).Control(2)=   "Line3"
      Tab(1).Control(2).Enabled=   0   'False
      Tab(1).Control(3)=   "Line4"
      Tab(1).Control(3).Enabled=   0   'False
      Tab(1).Control(4)=   "Label5"
      Tab(1).Control(4).Enabled=   0   'False
      Tab(1).Control(5)=   "Search(1)"
      Tab(1).Control(5).Enabled=   0   'False
      Tab(1).Control(6)=   "CloseButt(1)"
      Tab(1).Control(6).Enabled=   0   'False
      Tab(1).Control(7)=   "ReplaceButt"
      Tab(1).Control(7).Enabled=   0   'False
      Tab(1).Control(8)=   "MatchCase(1)"
      Tab(1).Control(8).Enabled=   0   'False
      Tab(1).Control(9)=   "WholeWord(1)"
      Tab(1).Control(9).Enabled=   0   'False
      Tab(1).Control(10)=   "Replace"
      Tab(1).Control(10).Enabled=   0   'False
      Tab(1).Control(11)=   "ReplaceAllButt"
      Tab(1).Control(11).Enabled=   0   'False
      Tab(1).ControlCount=   12
      Begin VB.CommandButton ReplaceAllButt
         Caption         =   "Replace &All"
         Enabled         =   0   'False
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   325
         Left            =   -70080
         TabIndex        =   10
         Top             =   2280
         Width           =   1095
      End
      Begin VB.TextBox Replace
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Left            =   -73800
         TabIndex        =   6
         Top             =   960
         Width           =   6015
      End
      Begin VB.CheckBox WholeWord
         Caption         =   "Find whole words onl&y"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   1
         Left            =   -74520
         TabIndex        =   8
         Top             =   1935
         Width           =   2295
      End
      Begin VB.CheckBox MatchCase
         Caption         =   "Matc&h case"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   1
         Left            =   -74520
         TabIndex        =   7
         Top             =   1680
         Width           =   1335
      End
      Begin VB.CommandButton ReplaceButt
         Caption         =   "&Replace"
         Enabled         =   0   'False
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   325
         Left            =   -71280
         TabIndex        =   9
         Top             =   2280
         Width           =   1095
      End
      Begin VB.CommandButton CloseButt
         Caption         =   "&Cancel"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   325
         Index           =   1
         Left            =   -68880
         TabIndex        =   11
         Top             =   2280
         Width           =   1095
      End
      Begin VB.TextBox Search
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Index           =   1
         Left            =   -73800
         TabIndex        =   5
         Top             =   600
         Width           =   6015
      End
      Begin VB.CheckBox WholeWord
         Caption         =   "Find whole words onl&y"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   0
         Left            =   480
         TabIndex        =   14
         Top             =   1940
         Width           =   2295
      End
      Begin VB.CheckBox MatchCase
         Caption         =   "Matc&h case"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Index           =   0
         Left            =   480
         TabIndex        =   1
         Top             =   1680
         Width           =   1335
      End
      Begin VB.CommandButton FindButt
         Caption         =   "&Find"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   325
         Left            =   4680
         TabIndex        =   3
         Top             =   2280
         Width           =   1335
      End
      Begin VB.CommandButton CloseButt
         Caption         =   "&Cancel"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   325
         Index           =   0
         Left            =   6120
         TabIndex        =   4
         Top             =   2280
         Width           =   1095
      End
      Begin VB.TextBox Search
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   285
         Index           =   0
         Left            =   1200
         TabIndex        =   0
         Top             =   600
         Width           =   6015
      End
      Begin VB.Label Label5
         Caption         =   "Replace with:"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   -74880
         TabIndex        =   17
         Top             =   1005
         Width           =   975
      End
      Begin VB.Line Line4
         BorderColor     =   &H00FFFFFF&
         X1              =   -73680
         X2              =   -67800
         Y1              =   1455
         Y2              =   1455
      End
      Begin VB.Line Line3
         X1              =   -73680
         X2              =   -67800
         Y1              =   1440
         Y2              =   1440
      End
      Begin VB.Label Label4
         Caption         =   "Search options"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   -74880
         TabIndex        =   16
         Top             =   1320
         Width           =   1215
      End
      Begin VB.Label Label3
         Caption         =   "Find what:"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   -74640
         TabIndex        =   15
         Top             =   645
         Width           =   855
      End
      Begin VB.Line Line2
         BorderColor     =   &H00FFFFFF&
         X1              =   1320
         X2              =   7200
         Y1              =   1450
         Y2              =   1450
      End
      Begin VB.Line Line1
         X1              =   1320
         X2              =   7200
         Y1              =   1440
         Y2              =   1440
      End
      Begin VB.Label Label2
         Caption         =   "Search options"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   120
         TabIndex        =   13
         Top             =   1320
         Width           =   1215
      End
      Begin VB.Label Label1
         Caption         =   "Find what:"
         BeginProperty Font
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   255
         Left            =   360
         TabIndex        =   12
         Top             =   645
         Width           =   855
      End
   End
End
Attribute VB_Name = "FindReplaceScr"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub CloseButt_Click(Index As Integer)
    Me.Hide
End Sub

Private Sub FindButt_Click()
    Dim lngResult As Long
    Dim lngPos As Long
    Dim intOptions As Integer
    ' Set search options
    If WholeWord(1).Value = 1 Then intOptions = intOptions + 2
    If MatchCase(1).Value = 1 Then intOptions = intOptions + 4

    If FindButt.Caption = "&Find" Then
    ' Search is going to be first time
   
    ' Get position of the searched word
    lngResult = MainScr.rtfText.Find(Search(0).Text, 0, , intOptions)

        If lngResult = -1 Then 'Text not found
            MsgBox "XenonPad has finished searching the document. The search item wasn't found.", vbInformation, "XenonPad"
            FindButt.Caption = "&Find" 'Set caption
            MainScr.EditFindNext.Enabled = False 'Disable Find Next menu item
        Else 'Text found
            MainScr.rtfText.SetFocus 'Set focus to rtfText
            ReplaceButt.Enabled = True 'Enable Replace button
            ReplaceAllButt.Enabled = True 'Enable ReplaceAll button
            FindButt.Caption = "&Find Next" 'Set new caption
            MainScr.EditFindNext.Enabled = True 'Enable Find Next menu
        End If
    Else 'Find Next
        lngPos = MainScr.rtfText.SelStart + MainScr.rtfText.SelLength
        lngResult = MainScr.rtfText.Find(Search(0).Text, lngPos, , intOptions)

        If lngResult = -1 Then 'Text not found
            MsgBox "XenonPad has finished searching the document.", vbInformation, "XenonPad"
            FindButt.Caption = "&Find" 'Set caption
            ReplaceButt.Enabled = False 'Disable Replace button
            ReplaceAllButt.Enabled = False 'Disable ReplaceAll button
            MainScr.EditFindNext.Enabled = False 'Disable Find Next menu
        Else 'Text found
            MainScr.rtfText.SetFocus 'Set focus to rtfText
            MainScr.EditFindNext.Enabled = True 'Enable Find Next menu
        End If
    End If
End Sub

Private Sub ReplaceAllButt_Click()
    Dim intCount As Integer
    Dim lngPos As Long
    Dim intOptions As Integer
    If Search(0).Text = "" Then Exit Sub
    ' Set search options
    If WholeWord(1).Value = 1 Then intOptions = intOptions + 2
    If MatchCase(1).Value = 1 Then intOptions = intOptions + 4

    intCount = 0
    lngPos = 0
    With MainScr
        Do
            If .rtfText.Find(Search(1).Text, lngPos, , intOptions) = -1 Then 'Text not fount
                If intCount > 0 Then 'Show how many replacments have been made
                    MsgBox "XenonPad has completed its search of the document and has made " & intCount & " replacements.", vbInformation, "XenonPad"
                End If
                FindButt.Caption = "&Find" 'Set caption
                ReplaceButt.Enabled = False 'Disable Replace button
                ReplaceAllButt.Enabled = False 'Disable ReplaceAll button
                Exit Do
            Else 'Text found
                lngPos = .rtfText.SelStart + .rtfText.SelLength
                intCount = intCount + 1 'Increase counter by 1
                .rtfText.SelText = Replace.Text 'Replace text
            End If
        Loop
    End With
End Sub

Private Sub ReplaceButt_Click()
    Dim lngResult As Long
    Dim lngPos As Long
    Dim intOptions As Integer

    ' Set search options
    If WholeWord(1).Value = 1 Then intOptions = intOptions + 2
    If MatchCase(1).Value = 1 Then intOptions = intOptions + 4
    If Search(1).Text = "" Then Exit Sub
    With MainScr
        .rtfText.SelText = Replace.Text 'Replace text
        ' Find next
        lngPos = .rtfText.SelStart + .rtfText.SelLength
        ' Get position of the searched word
        lngResult = .rtfText.Find(Search(1).Text, lngPos, , intOptions)

        If lngResult = -1 Then 'Text not found
            MsgBox "XenonPad has finished searching the document. The search item wasn't found.", vbInformation, "XenonPad"
            FindButt.Caption = "&Find" 'Set caption
            ReplaceButt.Enabled = False 'Disable Replace button
            ReplaceAllButt.Enabled = False 'Disable ReplaceAll button
        Else 'Text found
            .rtfText.SetFocus 'Set focus
        End If
    End With
End Sub

Private Sub Search_Change(Index As Integer)
    Search(1).Text = Search(0).Text
End Sub

Project Homepage: