[futurebasic] Re: [FB] Re: Search Edit Field

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

From: Alain Pastor <apastor@...>
Date: Fri, 23 Nov 2001 12:34:51 +0100
Hi,

Here is a possible entry for searching an edit field:

/*
     
     Searching field.
     This demo is supposed to search an edit field
     for a given string.
     The search can be performed from the start of
     the text or from the current position of the
     insertion point, it can be case sensitive or
     not, and finally you can choose to search for
     a single match or all matches.

                              Alain { 23/11/01 }
*/

begin enum = 1
_searchBtn
_quitBtn
_startBtn
_caseBtn
_allBtn
end enum

local fn doBuildWindow
dim as str255 myStr
myStr  = "Visit www.stazsoftware.com for the hottest news! "
myStr += "or you can mail staz at <mailto:staz@...>" + chr$(13)
myStr += "European residents may wish to visit
www.euro.futurebasic.com "
myStr += "or get info at <mailto:alain@...>"
window 1,"Searching test"
edit field 1, myStr , (10, 10)-(400,100), _noFramed 
setselect 0,0
edit field 2, "mail", (10,110)-(200,130), _framed
button _searchBtn,_activeBtn,"Search"        ,(100,140)-(200,160),_push
button _quitBtn  ,_activeBtn,"Quit"          ,( 10,140)-( 80,160),_push
button _startBtn ,_activeBtn,"From Start"    ,(100,170)-(250,185),_checkbox
button _caseBtn  ,_activeBtn,"Case Sensitive",(100,190)-(250,205),_checkbox
button _allBtn   ,_activeBtn,"Search All"    ,(100,210)-(250,225),_checkbox
end fn

local mode
local fn SearchField( id as long, toSearch as str255, found as long
,casing as boolean )
dim   teH  as ..TERec
dim @ txtH as handle

teH = tehandle( id )
long if teH
txtH = teH..hText
long if casing = _false
long if fn HandToHand( txtH ) = _noErr
UpperCaseText( [txtH], fn GetHandleSize( txtH ), _smCurrentScript )
UpperCaseText( @toSearch[1], toSearch[0], _smCurrentScript )
xelse
found = - 1 : exit fn
end if
end if
found = fn Munger( txtH, found, @toSearch[1], toSearch[0], _nil,
_nil )
if casing = _false then DisposeHandle( txtH )
xelse
found = -1
end if
end fn = found

local fn doSearch
dim as long    where, strLen
dim as str255  toSearch
dim as boolean casing, searchAll

toSearch = edit$( 2 )
strLen   = toSearch[0]
long if strLen
select button(_startBtn)
case _activeBtn : where = {[teHandle(1)]+ _teSelStart}
case _markedBtn : where = 0
end select
casing    = ( button( _caseBtn ) == _markedBtn )
searchAll = ( button( _allBtn )  == _markedBtn )
edit field 1
do
where = fn SearchField( 1, toSearch, where ,casing )
long if where > -1
setselect where, where + strLen
where += strLen
delay _sec 
end if
until where = -1 or searchAll = _false
xelse
beep
end if
end fn

local fn doDialog
dim as long evt, ref

evt = dialog(0)
ref = dialog(evt)
select evt
case _btnClick
select ref
case _searchBtn : fn doSearch
case _quitBtn   : gFBQuit = _zTrue
case _startBtn, _caseBtn, _allBtn
button ref, 1 + usr abs(  button( ref ) != _markedBtn )
end select
end select
end fn

// main test

fn doBuildWindow

on dialog fn doDialog
do
handleevents
until gFBQuit

-- 

Cheers

Alain

-----------------------------------------------------
FB^3 in Europe:  http://euro.futurebasic.com/
FB II Pouch:     http://www.pixmix.com/FB/outils.html
-----------------------------------------------------