Buscar y posicionarse en un campo memo.

HMG en Español

Moderator: Rathinagiri

User avatar
Pepe Ruano
Posts: 65
Joined: Fri Aug 16, 2013 11:31 am
DBs Used: DBF
Location: Almansa, Albacete - Spain
Contact:

Buscar y posicionarse en un campo memo.

Post by Pepe Ruano »

Hola tengo una base de datos que incluye un campo memo y quiero buscar un texto incluido en el campo memo y que se sitúe el cursor en el texto de la palabra buscada si la encontró. Lo que consigo hasta ahora es que me lleve al registro que la contiene, pero no se sitúa sobre el texto encontrado.
Alguno de ustedes me pueden decir cómo hacerlo?
Muchas gracias a todos. Y deseio que se encuentren todos bien de salud.

English Google Translator. :roll:

Search and position in a memo field.
Hello, I have a database that includes a memo field and I want to search for a text included in the memo field and place the cursor in the text of the search word if it found it. What I get so far is that it takes me to the record that contains it, but it does not go over the found text.
Can any of you tell me how to do it?
Thank you very much to all. And I wish you all are in good health.
Saludos - Regards
Pepe Ruano
hmg.ruano.org
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Buscar y posicionarse en un campo memo.

Post by AUGE_OHR »

hi,

you can call Windows "search & Replace" Dialog this Way

Code: Select all

STATIC cFind := ""  // Field-wide STATIC

   ON KEY CONTROL + F OF TXTEdit ACTION SearchText()

PROCEDURE SearchText()
   ( cFind , ; 
     FINDTEXTDIALOG ON ACTION FindReplTXTProc() FIND cFind CHECKDOWN lDown CHECKMATCHCASE lMatchCase CHECKWHOLEWORD lWholeWord )
RETURN

Code: Select all

PROCEDURE FindReplTXTProc()
LOCAL lSelectFindText
LOCAL aPosRange       := { 0, 0 }
LOCAL cFind         
LOCAL cHoleText, nPosi
STATIC nStart := 1
   IF FindReplaceDlg.RetValue == FRDLG_CANCEL                         // User Cancel or Close dialog
      RETURN
   ENDIF
   cFind := FindReplaceDlg.Find
   cReplace := FindReplaceDlg.Replace
   lDown := FindReplaceDlg.Down
   lMatchCase := FindReplaceDlg.MatchCase
   lWholeWord := FindReplaceDlg.WholeWord
   lSelectFindText := .T.

   cHoleText := TXTEdit.TXTCtrl.Value  // use your Control

   IF lDown = .T.
      nPosi := hb_at( UPPER( cFind ), UPPER( cHoleText ), nStart )
   ELSE
      nPosi := hb_rat( UPPER( cFind ), UPPER( cHoleText ), nStart )
   ENDIF

   IF nPosi > 0
      TXTEdit.TXTCtrl.CaretPos := nPosi  // use your Control
      nStart := nPosi + 1
   ELSE
      IF lDown = .T.
         MsgInfo( "EOF no more" )
         nStart := 1
      ELSE
         MsgInfo( "BOF no more" )
         nStart := LEN( cHoleText )
      ENDIF
   ENDIF

RETURN
have fun
Jimmy
User avatar
Pepe Ruano
Posts: 65
Joined: Fri Aug 16, 2013 11:31 am
DBs Used: DBF
Location: Almansa, Albacete - Spain
Contact:

Re: Buscar y posicionarse en un campo memo.

Post by Pepe Ruano »

AUGE_OHR wrote: Sun Jul 25, 2021 5:29 am hi,

you can call Windows "search & Replace" Dialog this Way

Code: Select all

STATIC cFind := ""  // Field-wide STATIC

   ON KEY CONTROL + F OF TXTEdit ACTION SearchText()

PROCEDURE SearchText()
   ( cFind , ; 
     FINDTEXTDIALOG ON ACTION FindReplTXTProc() FIND cFind CHECKDOWN lDown CHECKMATCHCASE lMatchCase CHECKWHOLEWORD lWholeWord )
RETURN

Code: Select all

PROCEDURE FindReplTXTProc()
LOCAL lSelectFindText
LOCAL aPosRange       := { 0, 0 }
LOCAL cFind         
LOCAL cHoleText, nPosi
STATIC nStart := 1
   IF FindReplaceDlg.RetValue == FRDLG_CANCEL                         // User Cancel or Close dialog
      RETURN
   ENDIF
   cFind := FindReplaceDlg.Find
   cReplace := FindReplaceDlg.Replace
   lDown := FindReplaceDlg.Down
   lMatchCase := FindReplaceDlg.MatchCase
   lWholeWord := FindReplaceDlg.WholeWord
   lSelectFindText := .T.

   cHoleText := TXTEdit.TXTCtrl.Value  // use your Control

   IF lDown = .T.
      nPosi := hb_at( UPPER( cFind ), UPPER( cHoleText ), nStart )
   ELSE
      nPosi := hb_rat( UPPER( cFind ), UPPER( cHoleText ), nStart )
   ENDIF

   IF nPosi > 0
      TXTEdit.TXTCtrl.CaretPos := nPosi  // use your Control
      nStart := nPosi + 1
   ELSE
      IF lDown = .T.
         MsgInfo( "EOF no more" )
         nStart := 1
      ELSE
         MsgInfo( "BOF no more" )
         nStart := LEN( cHoleText )
      ENDIF
   ENDIF

RETURN
AUGE_OHR wrote: Sun Jul 25, 2021 5:29 am hi,

you can call Windows "search & Replace" Dialog this Way

Code: Select all

STATIC cFind := ""  // Field-wide STATIC

   ON KEY CONTROL + F OF TXTEdit ACTION SearchText()

PROCEDURE SearchText()
   ( cFind , ; 
     FINDTEXTDIALOG ON ACTION FindReplTXTProc() FIND cFind CHECKDOWN lDown CHECKMATCHCASE lMatchCase CHECKWHOLEWORD lWholeWord )
RETURN

Code: Select all

PROCEDURE FindReplTXTProc()
LOCAL lSelectFindText
LOCAL aPosRange       := { 0, 0 }
LOCAL cFind         
LOCAL cHoleText, nPosi
STATIC nStart := 1
   IF FindReplaceDlg.RetValue == FRDLG_CANCEL                         // User Cancel or Close dialog
      RETURN
   ENDIF
   cFind := FindReplaceDlg.Find
   cReplace := FindReplaceDlg.Replace
   lDown := FindReplaceDlg.Down
   lMatchCase := FindReplaceDlg.MatchCase
   lWholeWord := FindReplaceDlg.WholeWord
   lSelectFindText := .T.

   cHoleText := TXTEdit.TXTCtrl.Value  // use your Control

   IF lDown = .T.
      nPosi := hb_at( UPPER( cFind ), UPPER( cHoleText ), nStart )
   ELSE
      nPosi := hb_rat( UPPER( cFind ), UPPER( cHoleText ), nStart )
   ENDIF

   IF nPosi > 0
      TXTEdit.TXTCtrl.CaretPos := nPosi  // use your Control
      nStart := nPosi + 1
   ELSE
      IF lDown = .T.
         MsgInfo( "EOF no more" )
         nStart := 1
      ELSE
         MsgInfo( "BOF no more" )
         nStart := LEN( cHoleText )
      ENDIF
   ENDIF

RETURN
Muchas gracias AUGE_OHR por tu rápida respuesta y solución, pero no me sirve. Busco algo para adaptarlo a mi código que quizás este al pero me sitúa en el registro correcto, pero no en el texto que ha encontrado. Repito muchas gracias por tu atención.

Thank you very much AUGE_OHR for your quick response and solution, but it does not work for me. I am looking for something to adapt it to my code that maybe this to but it puts me in the correct registry, but not in the text that it has found. I repeat thank you very much for your attention.
This is part of what I use now.
Esto es parte de lo que utilizo ahora.

Code: Select all

*------------------------------------------------------------------------------*
FUNCTION BuscaObs(cNombre)
*------------------------------------------------------------------------------*
Local nRec:= RECNO() , cFocus := OrdSetFocus(), cEncont, Result1, Info1
ordSetFocus( 1 )
	If Empty ( cNombre )
	  MSGINFO("Por favor introduzca nombre a buscar","Búsqueda de GESWEB")
	  FICHACLI.Text_Buscar.SetFocus
	  ordSetFocus( cFocus )
	  Retu Nil

	EndIf

	Locate for AT(cNombre,GESWEB->OBSERVACIO)>0
	IF !FOUND()
		MSGINFO("No se ha encontrado ninguna frase que coincida","Búsqueda de Observaciones")
		DBGOTO(nRec)
		FICHACLI.Text_Buscar.SetFocus
		Retu 
	ENDIF
	
  	WHILE FOUND( ) 
	 
			Result1 := AT(cNombre,GESWEB->OBSERVACIO)
			
			IF Result1 > 20
				 Result1 := Result1 - 20
			ENDIF
			
			Info1 :=  ALLTRIM(SUBSTR(GESWEB->OBSERVACIO, Result1 ,+ len(cNombre)+35	) )
			
			cEncont := "Nombre Ficha: "+ALLTRIM(GESWEB->NOMBRE) + CHR(13)  + CHR(13)  +  "Texto Encontrado ---->:  " + Info1
		IF MSGYESNO("Es esto lo que busca ? :" + CHR(13)  + CHR(13) +cEncont,"Texto Encontrado")
			GESWEBLEE()
			FICHACLI.Text_Buscar.Value :=""
			FICHACLI.Text_Buscar.SetFocus
			Retu 
		ENDIF	
		If ! MSGYESNO("Continuar Buscando?","Buscar")
      		DBGOTO(nRec)
			FICHACLI.Text_Buscar.Value :=""
			FICHACLI.Text_Buscar.SetFocus
			Retu
   		EndIf
		DBSKIP()
		LOCATE REST FOR AT(cNombre,GESWEB->OBSERVACIO)>0
  	ENDDO
	MSGINFO("No coinciden más palabras con ese nombre","Búsqueda de texto")
	DBGOTO(nRec)
	FICHACLI.Text_Buscar.Value :=""
	FICHACLI.Text_Buscar.SetFocus	
Return

Saludos - Regards
Pepe Ruano
hmg.ruano.org
User avatar
srvet_claudio
Posts: 2193
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Contact:

Re: Buscar y posicionarse en un campo memo.

Post by srvet_claudio »

Hola Pepe,
1) por las dudas, si estas usando unicode debes emplear las funciones unicode equivalentes HB_UAT y HMG_Len
2) No entiendo el IF de esta parte del codigo:

Code: Select all

Result1 := AT(cNombre,GESWEB->OBSERVACIO) // localiza el dato
			
IF Result1 > 20
	Result1 := Result1 - 20 // no sera esto ????
ENDIF
	
Info1 :=  ALLTRIM(SUBSTR(GESWEB->OBSERVACIO, Result1 ,+ len(cNombre)+35	) ) // extrae el dato
			
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Buscar y posicionarse en un campo memo.

Post by AUGE_OHR »

hi,
Pepe Ruano wrote: Sun Jul 25, 2021 12:22 am Hello, I have a database that includes a memo field and I want to search for a text included in the memo field and place the cursor in the text of the search word if it found it.
Value of Memo is "just" a String so you can use AT(), or HB_UAT() as Claudio say to find Position
Pepe Ruano wrote: Sun Jul 25, 2021 12:22 am What I get so far is that it takes me to the record that contains it, but it does not go over the found text.
do you mean "next match" :?:

Code: Select all

AT( <cSearch>, <cString>, [<nStart>], [<nEnd>] ) --> nPos 
you can use 3rd. Parameter <nStart> to search for "next match"

to "move" Cursor to found Position use

Code: Select all

   <ParentWindowName>.<ControlName>.CaretPos := nCaretPosition
---

that is all include in FINDTEXTDIALOG
have fun
Jimmy
User avatar
Pepe Ruano
Posts: 65
Joined: Fri Aug 16, 2013 11:31 am
DBs Used: DBF
Location: Almansa, Albacete - Spain
Contact:

Re: Buscar y posicionarse en un campo memo.

Post by Pepe Ruano »

Esto es lo que quiero, lo he puesto en fotos para intentar explicar mejor, lleva dos funciones de búsqueda, una por nombre primer campo a la izquierda y la otra búsqueda por el campo memo que es el último y pone observaciones. Y lo que quiero es como se visualiza en la última foto con el texto encontrado resaltado. Primero recorre la base de datos y muestra el registro, si es el que búscamos aceptamos y le decimos que sí y si no continúa buscando en los siguientes.
A ver si así os lo puedo explicar mejor y comprenden ustedes la idea.
De todas formas y como siempre muchas gracias a todos.

Now translated to English from Google :oops:

This is what I want, I have put it in photos to try to explain better, it has two search functions, one for the first field name on the left and the other search for the memo field which is the last and puts observations. And what I want is how it is displayed in the last photo with the found text highlighted. First it goes through the database and shows the record, if it is the one we are looking for, we accept it and we say yes and if it does not continue searching in the following ones.
Let's see if that way I can explain it to you better and you understand the idea.
Anyway, as always, thank you all very much.

Las fotos, the photos: Perdón pero están mal ordenadas, la primera debe ser la última que es lo que deseo y la última es la primera. :lol:
Sorry but they are badly ordered, the first must be the last which is what I want and the last is the first.
Attachments
07 Final result of the memo field that I want to be highlighted.
07 Final result of the memo field that I want to be highlighted.
07-searchgoodend.jpg (35.05 KiB) Viewed 1882 times
06 End Result the memo Field - No Good
06 End Result the memo Field - No Good
06-searchmemo1-result.jpg (34.29 KiB) Viewed 1882 times
05 1º Result Found in memo Field
05 1º Result Found in memo Field
05-searchmemo1-resultFound.jpg (38.84 KiB) Viewed 1882 times
04 1º Search by field memo
04 1º Search by field memo
04-searchmemo1.jpg (35.56 KiB) Viewed 1882 times
03 Result Search by name
03 Result Search by name
03-searchname1result.jpg (36.88 KiB) Viewed 1882 times
02 Search by name
02 Search by name
02-searchname1.jpg (35.86 KiB) Viewed 1882 times
01 List
01 List
01-listado.jpg (54.53 KiB) Viewed 1882 times
Saludos - Regards
Pepe Ruano
hmg.ruano.org
User avatar
Pepe Ruano
Posts: 65
Joined: Fri Aug 16, 2013 11:31 am
DBs Used: DBF
Location: Almansa, Albacete - Spain
Contact:

Re: Buscar y posicionarse en un campo memo.

Post by Pepe Ruano »

srvet_claudio wrote: Mon Jul 26, 2021 1:17 am Hola Pepe,
1) por las dudas, si estas usando unicode debes emplear las funciones unicode equivalentes HB_UAT y HMG_Len
2) No entiendo el IF de esta parte del codigo:

Code: Select all

Result1 := AT(cNombre,GESWEB->OBSERVACIO) // localiza el dato
			
IF Result1 > 20
	Result1 := Result1 - 20 // no sera esto ????
ENDIF
	
Info1 :=  ALLTRIM(SUBSTR(GESWEB->OBSERVACIO, Result1 ,+ len(cNombre)+35	) ) // extrae el dato
			
Claudio here I cut the memo text so that the memo does not exceed more than 20 characters.
Saludos - Regards
Pepe Ruano
hmg.ruano.org
User avatar
AUGE_OHR
Posts: 2060
Joined: Sun Aug 25, 2019 3:12 pm
DBs Used: DBF, PostgreSQL, MySQL, SQLite
Location: Hamburg, Germany

Re: Buscar y posicionarse en un campo memo.

Post by AUGE_OHR »

hi,

to "mark" found Text use

Code: Select all

   nStartIndex := AT( <cSearch>, <cString>, [<nStart>], [<nEnd>] )
   IF nStartIndex > 0
      nEndIndex := nStartIndex + LEN(cSearch)
      // handle of EDITBOX
      SendMessage(hWndEdit, EM_SETSEL, nStartIndex, nEndIndex)
have fun
Jimmy
User avatar
Pepe Ruano
Posts: 65
Joined: Fri Aug 16, 2013 11:31 am
DBs Used: DBF
Location: Almansa, Albacete - Spain
Contact:

Re: Buscar y posicionarse en un campo memo.

Post by Pepe Ruano »

AUGE_OHR wrote: Wed Jul 28, 2021 2:23 am hi,

to "mark" found Text use

Code: Select all

   nStartIndex := AT( <cSearch>, <cString>, [<nStart>], [<nEnd>] )
   IF nStartIndex > 0
      nEndIndex := nStartIndex + LEN(cSearch)
      // handle of EDITBOX
      SendMessage(hWndEdit, EM_SETSEL, nStartIndex, nEndIndex)
Hello again Jimmy, thank you very much for your contribution but I do not understand it well and I can not make it work or in which procedure to put it and the variables that you indicate I do not know what they correspond to. anyway thanks, I'll keep searching and testing.
Spanish:
Hola de nuevo Jimmy, muchas gracias por tu aporte pero no lo entiendo bien y no logro hacerle funcionar ni en que procedimiento hay que ponerlo y las variables que indicas tampoco sé a que corresponden. de todas formas gracias, seguiré buscando y haciendo pruebas.
Saludos - Regards
Pepe Ruano
hmg.ruano.org
User avatar
mustafa
Posts: 1158
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Contact:

Re: Buscar y posicionarse en un campo memo.

Post by mustafa »

Hola amigo Pepe Ruano: como estas ?

Siento mucho lo de tu enfermedad
https://www.hmgforum.com/viewtopic.php? ... it=mustafa

Espero que te encuentres mejor.

Sobre tu demanda de buscar dentro de un campo Memo, encontré
el código fuente publicado por Pablo César [ In Memoriam ]
https://www.hmgforum.com/viewtopic.php? ... ch+EDITBOX
y lo he adaptado un poco con base de Datos Memo
en el TEXTBOX => Buscar Bio , si la palabra está en el Campo Memo
Tanto con [ Enter ] + más Tabulador recorre el EDITBOX del Campo Memo
o con el Botón [ Search ] cada vez que pulsamos salta al próxima palabra
hasta que al final, sale el Mensaje => NO MORE "la Palabra Buscada"

Haber si puede servir esta opción ?
Un Cordial abrazo , que te mejores !
Mustafa

******************************* Google ********************************

Hello friend Pepe Ruano: how are you?

I'm very sorry about your illness
https://www.hmgforum.com/viewtopic.php? ... it=mustafa

I hope you feel better.

About your request to search within a Memo field, I found
the source code published by Pablo César [In Memoriam]
https://www.hmgforum.com/viewtopic.php? ... ch+EDITBOX
and I have adapted it a bit with Memo Database
in the TEXTBOX => Search Bio, if the word is in the Memo Field
With both [Enter] + plus Tab, it goes through the EDITBOX of the Memo Field
or with the [Search] Button, each time we press it jumps to the next word
until at the end, the Message comes out => NO MORE "the Search Word"

Ask if this option can be used?
A cordial hug, that you get better!
Mustafa
Attachments
Search_DBF_Memo.zip
(495.19 KiB) Downloaded 92 times
Pantallazo.jpg
Pantallazo.jpg (116.39 KiB) Viewed 1668 times
Post Reply