[futurebasic] Re: Search Edit Field

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : November 2001 : Group Archive : Group : All Groups

From: Ken Shmidheiser <k.shmidheiser@...>
Date: Sat, 24 Nov 2001 14:05:04 -0500
Michael asked:

>As near as I can tell a standardized routine for searching an edit
>field for a string is not on the FB^3 CD.  I hope I can built one
>this afternoon, but if anyone has one already I'd love to see it.

Here's one technique.

Ken

p.s. This is a barebones demo with no error checking. Watch for
e-mail line breaks and lost constant underscores.

'-------- BEGIN FB^3 CODE -------

BEGIN GLOBALS
DIM gC AS CONTAINER
END GLOBALS

LOCAL FN buildWindow
DIM AS RECT w1, ef1, ef2, ef3, ef4, ef5, b1, b2, b3
DIM AS STR31 s1, s2
EDIT = 2
SETRECT(  w1,   0,   0, 400, 300 )
SETRECT( ef1,  20,  20, 363, 100 )
SETRECT(  b1, 364,  18, 380, 102 )
SETRECT( ef2,  20, 120, 380, 134 )
SETRECT( ef3,  20, 140, 380, 160 )
SETRECT( ef4,  20, 180, 380, 194 )
SETRECT( ef5,  20, 200, 380, 220 )
SETRECT(  b2, 330, 260, 380, 280 )
SETRECT(  b3  230, 260, 315, 280 )

s1 = "Find this string:"
s2 = "Replace with this string:"

WINDOW-1,"",          @w1,_docNoGrow
EDIT FIELD -1,"",     @ef1,_framed,_leftJust
SCROLL BUTTON -1, 1, 1, 1, 1, @b1, _scrollOther
EDIT FIELD -2, s1,    @ef2,_statNoframed,_leftJust
EDIT FIELD -3,"",     @ef3,_framed,_leftJust
EDIT FIELD -4, s2,    @ef4,_statNoframed,_leftJust
EDIT FIELD -5,"",     @ef5,_framed,_leftJust
BUTTON 2,1,"Quit",    @b2,_shadow
BUTTON 3,1,"Replace", @b3,_push
WINDOW 1

EDIT FIELD 3

END FN

LOCAL FN REPLACE( @CPtr AS PTR,¬
                 oldSubStr AS STR255, ¬
                 newSubStr AS STR255 )
DIM found AS LONG
IF oldSubStr[0] = _nil OR CPtr.nil& = _nil THEN EXIT FN
found = FN Munger( CPtr.nil&, 0, @oldSubStr[1], ¬
oldSubStr[0], @newSubStr[1], newSubStr[0] )
END FN

LOCAL FN doSearch
DIM AS STR255 toBeReplacedStr, replaceWithStr

gC = EDIT$(1)

toBeReplacedStr = EDIT$(3)
replaceWithStr  = EDIT$(5)

FN REPLACE( gC, toBeReplacedStr, replaceWithStr )

EDIT$(1) = #gC
gC = ""

END FN

LOCAL FN doDialog
DIM AS INTEGER evnt,id
evnt = DIALOG(0)
id = DIALOG(evnt)
SELECT CASE( evnt )
CASE _wndClose
SELECT( id )
CASE 1 : END
END SELECT
CASE _btnClick
SELECT( id )
CASE 2 : END
CASE 3 : FN doSearch
END SELECT
CASE _efTab
SELECT( id )
CASE 3 : EDIT FIELD 5
CASE 5 : EDIT FIELD 3
END SELECT
END SELECT
END FN

ON DIALOG FN doDialog

FN buildWindow

// Here is some text for Edit Field 1

DIM AS STR255 t1Str, t2Str

t1Str = "This is some some sample text for ¬
Edit Field 1 that you can try a search and replace ¬
operation on. This demo uses FN REPLACE which is designed ¬
to work with a container but is here used to search ¬
an edit field."

t2Str = "I am trying to put some extra text into this ¬
edit field simply to activate the scroll button and ¬
be sure that it is activated and working as expected. ¬
This should allow for a thorough test."

EDIT$(1)  = t1Str + CHR$(13)
EDIT$(1, _maxInt, _maxInt) = CHR$(13) + t2Str

DO
HANDLEEVENTS
UNTIL 0
END

'---------- END CODE ----------