Consulta Ordwildseek

Forum help and suggestions to improve this forum.

Moderator: Rathinagiri

Post Reply
Mario Mansilla
Posts: 250
Joined: Wed Aug 13, 2008 2:35 pm
Location: Córdoba - Argentina
Been thanked: 2 times

Consulta Ordwildseek

Post by Mario Mansilla » Wed Jul 24, 2019 4:51 pm

Hola Amigos :
les adjunto un pequeño proyecto en el cual muestro un problema que tengo con la funcion Ordwildseek .
El problema consiste en que no encuentra la coincidencia con el primer registro .
Por ejemplo en el proyecto que les adjunto las base de datos ordenada por nombre :
ARTICULO 1
ARTICULO 2
ARTICULO 3
ARTICULO 4
ARTICULO 10
Si coloco como busqueda "1" solo me encuentra ARTICULO 10 cuando me deberia encontrar tambien ARTICULO 1
No se si estoy cometiendo algun error en los parametros de la funcion , si coloco como segundo parametro de la misma .F. directamente el programa se cuelga .
Espero que puedan ayudarme a solucionarlo

Saludos cordiales
Mario Mansilla

Hello friends :
I attached a small project in which I show a problem that I have with the Ordwildseek function.
The problem is that it does not match the first record.
For example in the project that I attach the databases sorted by name:
ARTICLE 1
ARTICLE 2
ARTICLE 3
ARTICLE 4
ARTICLE 10
If I put as search "1" only I find ARTICLE 10 when I should also find ARTICLE 1
I do not know if I am making a mistake in the parameters of the function, if I place it as the second parameter of it .F. directly the program crashes.
I hope you can help me solve it

Best regards
Mario Mansilla
Attachments
Ordwildseek.rar
(1.26 MiB) Downloaded 33 times

User avatar
danielmaximiliano
Posts: 2118
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 145 times
Been thanked: 20 times
Contact:

Post by danielmaximiliano » Thu Jul 25, 2019 2:52 am

*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. : +54901169026142
Telegram Name : DaNiElMaXiMiLiAnO

User avatar
gfilatov
Posts: 646
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 24 times
Been thanked: 216 times
Contact:

Post by gfilatov » Thu Jul 25, 2019 7:12 am

Hello Mario,

Please be so kind to try the following updated function:

Code: Select all

*--------------------
Static Procedure Buscar
*--------------------

Local cBusca  := "*" + AllTrim(Main.Text_1.Value) + "*"

Use Articulo
Articulo->(DbSetOrder(1))
Articulo->(DbGoTop())

DELETE ITEM ALL FROM Grid_1 OF Main

If !Empty(Main.Text_1.Value)
    If AllTrim(Main.Text_1.Value) $ Articulo->NOMBRE
      ADD ITEM { Codigo , Codigo , Nombre } TO Grid_1 OF Main
    Endif
    Do While Articulo->(OrdWildSeek( cBusca , .T. ))
      ADD ITEM { Codigo , Codigo , Nombre } TO Grid_1 OF Main
   EndDo
Endif

Close Articulo

Main.Grid_1.Value := Main.Grid_1.ItemCount
Main.Grid_1.Setfocus

Return 
Hope that helps :idea:
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

PeteWG
Posts: 148
Joined: Sun Mar 21, 2010 5:45 pm
Has thanked: 13 times
Been thanked: 50 times

Post by PeteWG » Mon Jul 29, 2019 8:37 am

Hi,

Although the code posted by Grigory should work, I think the logic of using ordWildSeek() goes like this:
The 1st time, you invoke the function without the second argument set, to check if you have at least one hit (i.e., a matching record).
and if succeed , you use the function in a loop with second argument (`<lContinue>`) set to .T., in order to locate all the rest matching keys, if any.
So, the `Buscar` procedure might shaped as follow:

Code: Select all

*--------------------
Static Procedure Buscar
*--------------------
Local cBusca  := "*" + AllTrim(Main.Text_1.Value) + "*"

Use Articulo
Articulo->(DbSetOrder(1))
Articulo->(DbGoTop())

DELETE ITEM ALL FROM Grid_1 OF Main

If !Empty(Main.Text_1.Value)
   IF Articulo->( OrdWildSeek( cBusca ) ) // 1st time call
      ADD ITEM { Codigo , Codigo , Nombre } TO Grid_1 OF Main
      Do While Articulo->(OrdWildSeek( cBusca , .T. )) // repeated call with .T.
         ADD ITEM { Codigo , Codigo , Nombre } TO Grid_1 OF Main
      EndDo 
   ENDIF
Endif

Main.Grid_1.Value := Main.Grid_1.ItemCount
Main.Grid_1.Setfocus

Return 
HTH,

regards,
Pete

Post Reply