find "macchina"se viene trovata la parola, viene posto un rettangolo attorno a quella parola (o frase).
ogni volta che contiamo a usare find, la ricerca prosegue dal punto in cui eravamo arrivati. Possiamo anche indicare di limitare la ricerca ad un unico campo field.
Se preferiamo fare una ricerca più carina possiamo sfruttare la proprietà foundchunk che contiene tutti i dati del testo appena trovato con find. Ci basterà sapere la proprietà rect del foundchunk per disegnarli attorno ciò che preferiamo.
L'esempio seguente usa find per trovare la parola, memorizza quante volte è stato già chiamato find, poi usa find empty per cancellare il rettangolo attorno alla parola cercata, e disegna ciò che preferiamo attorno alla a parola trovata. Ecco il codice commentato:
on mouseUp lock screen #blocchiamo lo schermo #controlliamo che non ci sia già il cerchio verde if exists(graphic "cerca") then delete graphic "cerca" end if #vediamo se abbiamo già cercato la parola e quante volte put the numfind of me into n if n is empty then put 1 into n end if put the text of field "paroladacercare" into parola put the oldparola of me into oldpar if oldpar is not parola then put 1 into n end if #cerchiamo la parola o frase repeat for n times find parola in field "testo" end repeat #salviamo la parola cercata set the oldparola of me to parola #vediamo cosa abbiamo trovato ed evidenziamo con un rettangolo arrotondato verde if the foundchunk is not empty then put the foundchunk into temp find empty create graphic "cerca" set the style of graphic "cerca" to "roundrect" set the linesize of graphic "cerca" to 3 set the foregroundcolor of graphic "cerca" to "green" put the formattedrect of temp into tempRect #facciamo un po' più grosso del rettangolo della parola add -4 to item 1 of tempRect add -4 to item 2 of tempRect add 4 to item 3 of tempRect add 4 to item 4 of tempRect set the rect of graphic "cerca" to tempRect add 1 to n set the numfind of me to n else #se non troviamo nulla azzeriamo il contatore della ricerca set the numfind of me to empty end if #sblocchiamo la grafica del programma unlock screenend mouseUp
ed ecco il risultato:


Nessun commento:
Posta un commento