?? frmsearch.frm
字號:
Me.Hide
End Sub
Private Sub btnNext_Click()
'declare vars
Dim SearchString As String
Dim FoundPos As Long
Dim FindFlag As Integer
'init local vars
frmMain.MsgMode = "Search"
SearchString = cboFind.Text
FoundPos = frmMain.ActiveForm.Text1.SelStart
FindFlag = 0
'assign values to flag var
If chkWholeWord.Value = 1 Then
FindFlag = FindFlag + 2
End If
If chkMatch.Value = 1 Then
FindFlag = FindFlag + 4
End If
frmSearchbtnNextClickJump1:
If FoundPos = Len(frmMain.ActiveForm.Text1.Text) Then
FoundPos = 0
Else
FoundPos = FoundPos + 1
End If
'find next occurance of SearchString
If FoundPos > StartPos Or (FoundPos = 0 And StartPos = 0) Then
'if cursor is positioned after StartPos
FoundPos = frmMain.ActiveForm.Text1.Find(SearchString, FoundPos, , FindFlag)
Else
'if cursor is positioned before StartPos
FoundPos = frmMain.ActiveForm.Text1.Find(SearchString, FoundPos, StartPos, FindFlag)
End If
'check for end of document or end of defined search area
If FoundPos = -1 Then
'if at end of doc, check from beginning of doc to StartPos
'If frmMain.ActiveForm.Text1.SelStart > StartPos Or frmMain.ActiveForm.Text1.SelStart = 0 Or frmMain.ActiveForm.Text1.SelStart = Len(frmMain.ActiveForm.Text1.Text) Then
FoundPos = frmMain.ActiveForm.Text1.Find(SearchString, 0, StartPos, FindFlag)
'End If
'if there are no more occurances of SearchString in current doc
'then switch to next doc in array
If FoundPos < 0 Or FoundPos = StartPos Then
'if this is the last/only doc in the array to be searched
If CurrentDocIndex = AFormsCount Then
btnReplace.Enabled = False
'if this proc called by btnNext_click() and not btnAll_Click()
If frmMain.ReplaceFlag = False Then
'make search form not topmost
success% = SetWindowPos(frmSearch.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
'hide search form
Me.Hide
MsgBox "The specified region has been searched.", 48
CurrentDocIndex = 0
'init global var for next search
frmMain.UserMsgChoice = ""
'show search form
Me.Show
'make search form not topmost
success% = SetWindowPos(frmSearch.hWnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
End If
'set focus back to for that search originated in (from StartFrom var)
For x = 0 To Forms.Count - 1
If Forms(x).Caption = StartForm Then
Forms(x).SetFocus
End If
Next x
're-initialize form so ending position is now starting position
'this allows the user to search the windows again.
Init
'this line used to tell btnAll_Click()(if it has called this proc)
'that the search has ended and it should stop looping
frmMain.UserMsgChoice = "Cancel"
'init btnReplace
If frmMain.ActiveForm.Text1.SelLength > 0 Then
btnReplace.Enabled = True
Else
btnReplace.Enabled = False
End If
Else
CurrentDocIndex = CurrentDocIndex + 1 'cycle to the next form index in array
AForms(CurrentDocIndex).SetFocus 'set focus to next form in array
AForms(CurrentDocIndex).Text1.SelStart = 0 'set cursor position to beginning of text
StartPos = 0 'init StartPos var to zero
FoundPos = -1
btnReplace.Enabled = True
GoTo frmSearchbtnNextClickJump1
End If
End If
Else
btnReplace.Enabled = True
End If
End Sub
Private Sub btnReplace_Click()
Dim StartPos As Long
Dim T As RichTextBox
Set T = frmMain.ActiveForm.Text1
'check for highlighted text
If T.SelLength < 1 Then
MsgBox "You must select some text to replace.", 16, "REPLACE TEXT ERROR"
Exit Sub
End If
'assing cursor starting pos to local var
StartPos = T.SelStart
'replace highlighted text with contents of Replace With combo
If cboReplace.Text = "" Then
T.SelText = ""
Else
T.SelText = cboReplace.Text
End If
'reset cursor position to end of text used for replacement
T.SelStart = StartPos + Len(cboReplace.List(cboReplace.ListIndex))
End Sub
Private Sub cboFind_LostFocus()
Dim Flag As Boolean
Flag = False
'if no items in combo, add current text
If cboFind.ListCount < 1 Then
cboFind.AddItem cboFind.Text
cboFind.ListIndex = cboFind.NewIndex
End If
'make sure the current string has been added to the combo
For x = 0 To cboFind.ListCount - 1
If cboFind.Text = cboFind.List(x) Then
Flag = True
End If
Next x
'if current text is not an item in combo
If Flag = False Then
'add item to combo first
cboFind.AddItem cboFind.Text
'Init Search form (resests AForms array and related counters)
'Note: Changing the search text is a logical reset of the search
'therefore the Init procedure is called. This will cause the
'form stored in StartForm to use the currently active form instead
'of the searches originator.
Init
End If
End Sub
Private Sub cboReplace_LostFocus()
Dim Flag As Boolean
Flag = False
'if no items in combo, add current text
If cboReplace.ListCount < 1 Then
cboReplace.AddItem cboReplace.Text
cboReplace.ListIndex = cboReplace.NewIndex
End If
'make sure the current string has been added to the combo
For x = 0 To cboReplace.ListCount - 1
If cboReplace.Text = cboReplace.List(x) Then
Flag = True
End If
Next x
'if current text is not an item in combo
If Flag = False Then
'add item to combo
cboReplace.AddItem cboReplace.Text
cboReplace.ListIndex = cboReplace.NewIndex
End If
End Sub
Private Sub optAllDocs_Click()
'destroy existing array
DestroyFormArray
If optAllDocs.Value = True Then
'add current form to array
For x = 0 To Forms.Count - 1
If Forms(x).Caption = StartForm Then
ReDim Preserve AForms(AFormsCount) As Form
Set AForms(AFormsCount) = frmMain.ActiveForm
End If
Next x
'add all other forms to array
'1 can be used since it refers to MDI parent form that can't be searched
For x = 1 To Forms.Count - 1
If Not Forms(x).Caption = StartForm Then
'look for "Searchable" in the form's tag property
'this is to insure that no system forms are added to the array
If InStr(Forms(x).Tag, "Searchable") > 0 Then
AFormsCount = AFormsCount + 1
ReDim Preserve AForms(AFormsCount) As Form
Set AForms(AFormsCount) = Forms(x)
End If
End If
Next x
End If
'init CurrentDocIndex to zero
CurrentDocIndex = 0
End Sub
Private Sub optCurDoc_Click()
'destroy existing array
DestroyFormArray
'init AFormsCount to zero
'this must come after DestroyFormArray since that method uses this
'number for its loop
AFormsCount = 0
'add current form to array
For x = 0 To Forms.Count - 1
If Forms(x).Caption = StartForm Then
ReDim Preserve AForms(AFormsCount) As Form
Set AForms(AFormsCount) = frmMain.ActiveForm
End If
Next x
'init CurrentDocIndex back to zero
CurrentDocIndex = 0
End Sub
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -