Here is some sample code:
'---- Find and Replace -- Pierre Zippi, 1999
_searchAndReplace = 2
_MainWnd = 1
_MainEdit1 = 1
_MainEdit2 = 2
_MainEdit3 = 3
DIM gProgramEnds
DIM size&
DIM hndl&
END GLOBALS
'-------------------------------------------------------------------------------
CLEAR LOCAL
DIM replStr&, replLen&
DIM findStr&, findLen&
DIM found&
LOCAL FN Mung&(tgt$,repl$,txtH&,start&,mungMode)
' Munger function replaces the target text contained in tgt$
' with the replacement text contained in repl$ after the start search location
' (start&) in TEXT handle txtH& returns the found position in txtH&
' note: if tgtPtr&=NIL, repl$ will replace the specified number of
' characters beginning at the starting position,
' regardless of what they contain
' note: if tgtLen&=0, repl$ is inserted at the starting position
' without replacing anything
' note: if tgtLen&<0 and tgtPtr&=NIL, repl$ is inserted at the
' starting position, replacing everything to the end of the
' destination text.
' note: if replPtr&=NIL, munger will return (in found&) the position
' of the first occurrence of tgt$ without any replacement
' note: if replLen& is 0 but replPtr& is NOT NIL, Munger will deletetgt$
' from the destination text (txtH&)
findStr& = @tgt$+1
findLen& = PEEK(@tgt$)
replStr& = @repl$+1
replLen& = PEEK(@repl$)
found&=FN MUNGER(txtH&,start&,findStr&,findLen&,replStr&,replLen&)
END FN = found&
CLEAR LOCAL
LOCAL FN FindAndReplace
count=0
mungMode=2 'search and replace
size&=FN GETHANDLESIZE(hndl&) 'may have changed with last edit
LONG IF size& < 32000
teHndl&=TEHANDLE(1)
textH& = teHndl&..teTextH& 'get text handle
strSize&=FN GETHANDLESIZE(textH&)
found&=3 'skip size btyes
start&=found&
tgt$= EDIT$(2)
repl$= EDIT$(3)
tgtLen=LEN(tgt$)
repLen=LEN(repl$)
DO
found&=FN Mung&(tgt$,repl$,txtH&,start&,mungMode)
start&=found&+1
INC(count) 'track number of changes
UNTIL found&=-1 OR found&>=strSize&
CALL TECALTEXT(teHndl&) 'recalculate field info
CALL INVALRECT(#[teHndl&]+_teViewRect) 'force redraw
END IF
END FN
LOCAL FN Build
test$="1@@2@@3@@4@@5@@6"
WINDOW 1,"Find and Replace",(10,45)-(310,450),(_doc), 1
TEXT _monaco,9,0,0:COLOR=_zBlack
PRINT %(10,40) "Command-period to quit"
'------
BUTTON 2,1,"Replace",(110,7)-(160,25),_push_useWFont
EDIT FIELD _MainEdit1,test$,(0,100)-(300,300),_framed, _leftJust
EDIT FIELD _MainEdit2,"@@",(10,11)-(50,22),_framedNoCR, _leftJust
EDIT FIELD _MainEdit3,"@",(60,11)-(100,22),_framedNoCR, _leftJust
SCROLL BUTTON -1,1,1,1,1,,_scrollVert
EDIT TEXT _monaco, 9,
EDIT FIELD _MainEdit2
END FN
'-------------------------------------
CLEAR LOCAL
DIM efID%
DIM rect;8
LOCAL FN MainDialog(dlgEvent%,dlgID%)
SELECT dlgEvent%
CASE _wndClose
WINDOW CLOSE _MainWnd
CASE _wndActivate
IF dlgID%>0 THEN WINDOW OUTPUT #ABS(dlgID%):
CASE _wndClick
WINDOW #dlgID%
CASE _wndRefresh
'FN MainRefresh
CASE _btnClick
SELECT dlgID%
CASE 1 'scroll
'current% = BUTTON(1)
'SCROLL BUTTON #1, current%
CASE 2 'search and replace
FN FindAndReplace
END SELECT
CASE _efShiftTab, _efUpArrow, _efLeftArrow
efID%=WINDOW(_efNum)
efID%=efID%-1
IF efID%=0 THEN efID%= 3
EDIT FIELD efID%
CASE _efTab, _efDownArrow, _efRightArrow
efID%=WINDOW(_efNum)
efID%=(efID% MOD 3)+1
EDIT FIELD efID%
CASE _efClick
EDIT FIELD dlgID%
END SELECT
END FN
'-------------------------------------
LOCAL FN quitProgram
gProgramEnds=_True
END FN
LOCAL FN doDialog 'Dialog function template
evnt = DIALOG(0)
id = DIALOG(evnt)
IF evnt=_wndClick THEN WINDOW id ' --- activate a window if you
click ON it
W=WINDOW(_outputWnd) ' --- get current winodw
SELECT W
CASE _MainWnd
FN MainDialog(evnt,id)
END SELECT
END FN
FN Build
ON DIALOG FN doDialog
DO
HANDLEEVENTS
UNTIL gProgramEnds
Pierre A. Zippi