<http://forum.pspad.com/read.php?f=2&i=10431&t=10426> 
----------------------------------------------------------------

Do to popular demand, I created a VBScript method for performing searches
on active document and returns the first position of the matching text.  I
have _NOT_ tested it.  If you have any questions or comment please post
them here.


Sub FindPos
    pattern = InputBox("Find: ", module_name, "Pspad")
    aPos = GetStrPos(pattern, False)
    If IsArray(aPos) Then
        '// Found a match, now move caret to match.
        Set editor = newEditor()
        editor.assignActiveEditor
        editor.setCaretPos aPos(0), aPos(1)
        '// Select match
        For i = 1 to Len(pattern)
            editor.command("ecSelRight")    
        Next 
    Else 
        MsgBox "No match found.", 0, module_name & "::FindPos"
    End If
End Sub

'// Return position of string within active editor.
'//
'// @param string Search patten as palin text RegEx is not supported on
this one
'// @param bool   Whether serching for the top of editor or current caret
y 
'//               position.
'// @return array/false On match array(x: integer, y: integer)
'// @access private
Private Function GetStrPos(pattern, serchFromTop)
    Set editor = newEditor()
    editor.assignActiveEditor
    '// Get all text
    allText  = editor.Text
    lines = Split(allText, Chr(13))
    currCaretX = editor.caretX
    currCaretY = editor.caretY
    '// i is the current line number.
    i = 0
    '// Set are default value
    GetStrPos = False
    For Each line in lines
        i = i + 1
        If i => currCaretY Or serchFromTop = True Then
            iPos = InStr(currCaretX, line, pattern, 1)
            If iPos > 0 Then
                '// We found a match lest more to a position just before
the 
                '// match.
                iPos = iPos - 1
                GetStrPos = array(iPos, i)
                Exit For
            End If  
        End If
    Next
End Function


[%sig%]

-- 
PSPad freeware editor http://www.pspad.com

Reply via email to