IT-Consultant: Charles Pegge > OxygenBasic Examples

Find / Replace / ReplaceAll functions for scintillla control

(1/3) > >>

Zlatko Vid:
In old forum we talk about proper way to get this work
me and Roland or someone else ..i really canot remember
Gary beeane examples are strange and i cannot get it to work
any better solutions ?

i am using this 3 functions


--- Code: ---   Sub FindNext () as long
INT loc=1,temp
'search next
'loc=SENDMESSAGE hsci,SCI_SEARCHNEXT,temp,GetText(fwed1)
   ' print "search:" + str(loc)
if loc <> 0
temp=SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
    print "is selected-LOC: " + str(loc)
else
loc=SENDMESSAGE hsci,SCI_GETSELECTIONSTART,0,0
    print "selection start-LOC: " + str(loc)
end if

SENDMESSAGE hsci, SCI_SETANCHOR, temp ,0
SENDMESSAGE hsci, SCI_SETCURRENTPOS,loc,0
SENDMESSAGE hsci, SCI_SEARCHANCHOR,0,0

'temp = SCFIND_WHOLEWORD
' print "TEMP: " + str(temp)
loc=SENDMESSAGE hsci,SCI_SEARCHNEXT, SCFIND_WHOLEWORD, GetText(fwed1)
 print "SEARCH-NEXT: " + str(loc)
'---------------------------------------------
IF loc > 0
      SENDMESSAGE hsci,SCI_SCROLLCARET,0,0
ELSE
Msgbox "No matches found","Search"
Return 0
END IF
'-------------------------------------------
Return loc
End Sub
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Function ReplaceOnce(RepeatS As Long) As Long
If FindNext() = 0
Return 0
End if
SENDMESSAGE hsci,SCI_REPLACESEL,0,GetText(fwed2)
Return 1
End Function
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub ReplaceAll
   dim iResult As Long
   'If FindNext() = 0 then
   ' Exit Function
   'End If
   iResult = ReplaceOnce(1)
If iResult = 0 then Exit Sub
   While iResult =1
      FindNext()
      iResult = ReplaceOnce(1)                   
   Wend
   MsgBox " All words Replaced!","Info"
End Sub
--- End code ---

Zlatko Vid:
currently i am in process of reconstruction of
this 3 functions...testing each step to see how exactlly work
if you have some suggestion let me known..


--- Code: --- Sub FindNext () as long
INT loc,temp
'search next
'loc=SENDMESSAGE hsci,SCI_SEARCHNEXT,temp,GetText(fwed1)
   ' print "search:" + str(loc)
'if loc = 1
'loc=SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
 '   print "is selected-LOC: " + str(loc)
'else
'loc=SENDMESSAGE hsci,SCI_GETSELECTIONSTART,0,0
'    print "selection start-LOC: " + str(loc)
'end if

'SENDMESSAGE hsci, SCI_SETANCHOR, loc ,0
'SENDMESSAGE hsci, SCI_SETCURRENTPOS,loc,0
'SENDMESSAGE hsci, SCI_SEARCHANCHOR,0,0

'temp = SCFIND_WHOLEWORD
' print "TEMP: " + str(temp)
loc = SENDMESSAGE hsci,SCI_SEARCHNEXT, SCFIND_WHOLEWORD, GetText(fwed1)
 print "SEARCH-NEXT: " + str(loc)
'---------------------------------------------
IF loc > 0
      SENDMESSAGE hsci,SCI_SCROLLCARET,0,0
ELSE
Msgbox "No matches found","Search"
Return 0
END IF
'>>>>>>>>>>>
Return loc
'>>>>>>>>>>
End Sub
'------------------------------------------------

Function ReplaceOnce(RepeatStep As Long) As Long
int curloc,selected

If FindNext() = 0
Return 0
Else
   selcted = SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
   print "SELECTED:" + str(selected)
   curloc =  : print "CURRENT LOCATION:" + str(curloc)
End if

SENDMESSAGE hsci,SCI_REPLACESEL, curloc ,GetText(fwed2)

Return 1
End Function
'>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Sub ReplaceAll
   dim iResult As Long
   'If FindNext() = 0 then
   ' Exit Function
   'End If
   iResult = ReplaceOnce(1)
If iResult = 0 then Exit Sub
   While iResult =1
      FindNext()
      iResult = ReplaceOnce(1)                   
   Wend
   MsgBox " All words Replaced!","Info"
End Sub
--- End code ---

Zlatko Vid:

--- Code: ---Ouhhh

After testing and testing and trying
(i broke my fingers with typing  ;D )
i get it FindNext()  and  ReplaceOnce() functions to work
 
--- End code ---


[Theo] SORRY. I pressed the wrong button and destroyed your post.
This was by mistake. Anyway ...
You can possibly save time, if you download Jose's CSED-Editor here in the Forum, it is also based on Scintilla and you can just copy a lot of the common subroutines from there.

Zlatko Vid:
Ahh
no problem i already posted it on my forum too..
C_SED is great editor and i looked in code ..but is very complex

here are routines:

Zlatko Vid:
Main problem is in function FindNext() as long

I am not sure what move selction to next slection position
looks that work ...hmmm


--- Quote ---Sub FindNext () as long
static INT loc,temp
if loc
loc=SENDMESSAGE hsci,SCI_GETSELECTIONEND,0,0
'print "is selected-LOC: " + str(loc)
else
loc=SENDMESSAGE hsci,SCI_GETSELECTIONSTART,0,0
' print "selection start-LOC: " + str(loc)
end if

SENDMESSAGE hsci, SCI_SETANCHOR, loc ,0
SENDMESSAGE hsci, SCI_SETCURRENTPOS,loc,0
SENDMESSAGE hsci, SCI_SEARCHANCHOR,0,0

temp = SCFIND_WHOLEWORD
' print "TEMP: " + str(temp)
loc=SENDMESSAGE hsci,SCI_SEARCHNEXT,temp,GetText(fwed1)
' print "SEARCH-NEXT: " + str(loc)
'---------------------------------------------
IF loc > -1
      SENDMESSAGE hsci,SCI_SCROLLCARET,0,0
ELSE
   Msgbox "No matches found","Search"
Return 0
END IF
'-------------------------------------------
Return loc
End Sub
--- End quote ---

Navigation

[0] Message Index

[#] Next page

Go to full version