Option Explicit
Public cScintilla As SCIVB
Private Sub cmdClose_Click()
Unload Me
End Sub
Private Sub cmdFindNext_Click()
cScintilla.FindText cmbFind.Text, False, False, chkWrap.Value, chkCase.Value, False, chkWhole.Value, chkRegExp.Value
AddCombo cmbFind, cmbFind.Text
AddCombo cmbReplace, cmbReplace.Text
End Sub
Private Sub cmdReplace_Click()
Dim iGetPos As Long
cScintilla.FindText cmbFind.Text, False, False, chkWrap.Value, chkCase.Value, False, chkWhole.Value, chkRegExp.Value
If cmbReplace.Text <> "" Then
cScintilla.ReplaceSel cmbReplace.Text
cScintilla.SetSel cScintilla.GetCurPos - 1, cScintilla.GetCurPos - 1 + Len(cmbReplace.Text)
Else
iGetPos = cScintilla.GetCurPos
cScintilla.ReplaceSel ""
cScintilla.SetSel iGetPos - LenB(cmbFind.Text), iGetPos - LenB(cmbFind.Text)
'cScintilla.SendEditor SCI_SETTARGETSTART, iGetPos + 1
'cScintilla.SendEditor SCI_SETTARGETEND, iGetPos + Len(cmbFind.Text)
cScintilla.FindText cmbFind.Text, False, False, chkWrap.Value, chkCase.Value, False, chkWhole.Value, chkRegExp.Value
End If
AddCombo cmbFind, cmbFind.Text
AddCombo cmbReplace, cmbReplace.Text
End Sub
Private Sub cmdReplaceAll_Click()
Dim iRep As Long
iRep = cScintilla.ReplaceAll(cmbFind.Text, cmbReplace.Text, chkCase.Value, chkRegExp.Value, chkWhole.Value, False)
If iRep > 0 Then
lblReplace.Caption = "Replaced " & iRep & " times"
Else
MsgBox "No instances of " & """" & cmbFind.Text & """" & " were found in document"
End If
AddCombo cmbFind, cmbFind.Text
AddCombo cmbReplace, cmbReplace.Text
End Sub
Private Sub Form_Load()
ComboLoadHistory cmbFind
ComboLoadHistory cmbReplace
If cmbFind.ListCount > 0 Then
cmbFind.Text = cmbFind.List(0)
End If
If cmbReplace.ListCount > 0 Then
cmbReplace.Text = cmbReplace.List(0)
End If
Me.Left = GetSetting("ScintillaClass", "Settings", "ReplaceLeft", (Screen.Width - Me.Width) \ 2)
Me.Top = GetSetting("ScintillaClass", "Settings", "ReplaceTop", (Screen.Height - Me.Height) \ 2)
chkCase.Value = GetSetting("ScintillaClass", "Settings", "RchkCase", 0)
chkRegExp.Value = GetSetting("ScintillaClass", "Settings", "RchkRegEx", 0)
chkWhole.Value = GetSetting("ScintillaClass", "Settings", "RchkWhole", 0)
chkWrap.Value = GetSetting("ScintillaClass", "Settings", "RchkWrap", 1)
End Sub
Private Sub Form_Unload(Cancel As Integer)
SaveSetting "ScintillaClass", "Settings", "ReplaceLeft", Me.Left
SaveSetting "ScintillaClass", "Settings", "ReplaceTop", Me.Top
SaveSetting "ScintillaClass", "Settings", "RchkCase", chkCase.Value
SaveSetting "ScintillaClass", "Settings", "RchkRegEx", chkRegExp.Value
SaveSetting "ScintillaClass", "Settings", "RchkWhole", chkWhole.Value
SaveSetting "ScintillaClass", "Settings", "RchkWrap", chkWrap.Value
cScintilla.SetFocus
End Sub